blob: f790514a147ddcba91e1cea86a1583cce2339224 [file] [log] [blame]
Thomas Gleixner8e8e69d2019-05-29 07:17:59 -07001// SPDX-License-Identifier: GPL-2.0-only
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05302/*
3 * byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform
4 *
5 * Copyright (C) 2014 Intel Corp
6 * Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05309 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 */
11
Hans de Goede6a7c05e2018-05-08 17:35:54 +020012#include <linux/i2c.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053013#include <linux/init.h>
14#include <linux/module.h>
Takashi Iwai9f2cf732017-04-23 09:22:56 +020015#include <linux/moduleparam.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053016#include <linux/platform_device.h>
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060017#include <linux/acpi.h>
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -050018#include <linux/clk.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053019#include <linux/device.h>
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060020#include <linux/dmi.h>
Hans de Goede77323102018-05-13 09:24:28 +020021#include <linux/input.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053022#include <linux/slab.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053023#include <sound/pcm.h>
24#include <sound/pcm_params.h>
25#include <sound/soc.h>
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060026#include <sound/jack.h>
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050027#include <sound/soc-acpi.h>
Hans de Goedea3ad2912018-05-13 09:24:26 +020028#include <dt-bindings/sound/rt5640.h>
Jie Yange56c72d2015-04-02 15:37:02 +080029#include "../../codecs/rt5640.h"
Jie Yangb97169d2015-04-02 15:37:04 +080030#include "../atom/sst-atom-controls.h"
Pierre-Louis Bossart536cfd22019-05-30 06:50:11 -050031#include "../common/soc-intel-quirks.h"
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053032
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060033enum {
34 BYT_RT5640_DMIC1_MAP,
35 BYT_RT5640_DMIC2_MAP,
36 BYT_RT5640_IN1_MAP,
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -050037 BYT_RT5640_IN3_MAP,
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060038};
39
Hans de Goede77323102018-05-13 09:24:28 +020040enum {
41 BYT_RT5640_JD_SRC_GPIO1 = (RT5640_JD_SRC_GPIO1 << 4),
42 BYT_RT5640_JD_SRC_JD1_IN4P = (RT5640_JD_SRC_JD1_IN4P << 4),
43 BYT_RT5640_JD_SRC_JD2_IN4N = (RT5640_JD_SRC_JD2_IN4N << 4),
44 BYT_RT5640_JD_SRC_GPIO2 = (RT5640_JD_SRC_GPIO2 << 4),
45 BYT_RT5640_JD_SRC_GPIO3 = (RT5640_JD_SRC_GPIO3 << 4),
46 BYT_RT5640_JD_SRC_GPIO4 = (RT5640_JD_SRC_GPIO4 << 4),
47};
Irina Tirdeadf1a2772016-08-12 16:27:57 -050048
Hans de Goede77323102018-05-13 09:24:28 +020049enum {
50 BYT_RT5640_OVCD_TH_600UA = (6 << 8),
51 BYT_RT5640_OVCD_TH_1500UA = (15 << 8),
52 BYT_RT5640_OVCD_TH_2000UA = (20 << 8),
53};
54
55enum {
56 BYT_RT5640_OVCD_SF_0P5 = (RT5640_OVCD_SF_0P5 << 13),
57 BYT_RT5640_OVCD_SF_0P75 = (RT5640_OVCD_SF_0P75 << 13),
58 BYT_RT5640_OVCD_SF_1P0 = (RT5640_OVCD_SF_1P0 << 13),
59 BYT_RT5640_OVCD_SF_1P5 = (RT5640_OVCD_SF_1P5 << 13),
60};
61
62#define BYT_RT5640_MAP(quirk) ((quirk) & GENMASK(3, 0))
63#define BYT_RT5640_JDSRC(quirk) (((quirk) & GENMASK(7, 4)) >> 4)
64#define BYT_RT5640_OVCD_TH(quirk) (((quirk) & GENMASK(12, 8)) >> 8)
65#define BYT_RT5640_OVCD_SF(quirk) (((quirk) & GENMASK(14, 13)) >> 13)
66#define BYT_RT5640_JD_NOT_INV BIT(16)
67#define BYT_RT5640_MONO_SPEAKER BIT(17)
68#define BYT_RT5640_DIFF_MIC BIT(18) /* default is single-ended */
69#define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */
70#define BYT_RT5640_SSP0_AIF1 BIT(20)
71#define BYT_RT5640_SSP0_AIF2 BIT(21)
72#define BYT_RT5640_MCLK_EN BIT(22)
73#define BYT_RT5640_MCLK_25MHZ BIT(23)
74
Hans de Goede96a388fe2018-05-13 09:24:30 +020075#define BYTCR_INPUT_DEFAULTS \
76 (BYT_RT5640_IN3_MAP | \
Hans de Goede56ff4402018-05-13 09:24:31 +020077 BYT_RT5640_JD_SRC_JD1_IN4P | \
78 BYT_RT5640_OVCD_TH_2000UA | \
79 BYT_RT5640_OVCD_SF_0P75 | \
Hans de Goede96a388fe2018-05-13 09:24:30 +020080 BYT_RT5640_DIFF_MIC)
81
Hans de Goede77323102018-05-13 09:24:28 +020082/* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
83#define MAX_NO_PROPS 6
Hans de Goede6a7c05e2018-05-08 17:35:54 +020084
Irina Tirdeadf1a2772016-08-12 16:27:57 -050085struct byt_rt5640_private {
Hans de Goede77323102018-05-13 09:24:28 +020086 struct snd_soc_jack jack;
Irina Tirdeadf1a2772016-08-12 16:27:57 -050087 struct clk *mclk;
88};
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -050089static bool is_bytcr;
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060090
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -060091static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN;
Pierre-Louis Bossart2fb2a192019-04-19 15:12:17 -050092static int quirk_override = -1;
93module_param_named(quirk, quirk_override, int, 0444);
Takashi Iwai9f2cf732017-04-23 09:22:56 +020094MODULE_PARM_DESC(quirk, "Board-specific quirk override");
Irina Tirdeadf1a2772016-08-12 16:27:57 -050095
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -050096static void log_quirks(struct device *dev)
97{
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -050098 int map;
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -050099 bool has_mclk = false;
100 bool has_ssp0 = false;
101 bool has_ssp0_aif1 = false;
102 bool has_ssp0_aif2 = false;
103 bool has_ssp2_aif2 = false;
104
105 map = BYT_RT5640_MAP(byt_rt5640_quirk);
106 switch (map) {
107 case BYT_RT5640_DMIC1_MAP:
108 dev_info(dev, "quirk DMIC1_MAP enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500109 break;
110 case BYT_RT5640_DMIC2_MAP:
111 dev_info(dev, "quirk DMIC2_MAP enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500112 break;
113 case BYT_RT5640_IN1_MAP:
114 dev_info(dev, "quirk IN1_MAP enabled\n");
115 break;
116 case BYT_RT5640_IN3_MAP:
117 dev_info(dev, "quirk IN3_MAP enabled\n");
118 break;
119 default:
120 dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
121 break;
122 }
Hans de Goede77323102018-05-13 09:24:28 +0200123 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
124 dev_info(dev, "quirk realtek,jack-detect-source %ld\n",
125 BYT_RT5640_JDSRC(byt_rt5640_quirk));
126 dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n",
127 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
128 dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n",
129 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
130 }
131 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
132 dev_info(dev, "quirk JD_NOT_INV enabled\n");
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500133 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500134 dev_info(dev, "quirk MONO_SPEAKER enabled\n");
Hans de Goedea3ad2912018-05-13 09:24:26 +0200135 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
136 dev_info(dev, "quirk DIFF_MIC enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500137 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
138 dev_info(dev, "quirk SSP0_AIF1 enabled\n");
139 has_ssp0 = true;
140 has_ssp0_aif1 = true;
141 }
142 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
143 dev_info(dev, "quirk SSP0_AIF2 enabled\n");
144 has_ssp0 = true;
145 has_ssp0_aif2 = true;
146 }
147 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
148 dev_info(dev, "quirk SSP2_AIF2 enabled\n");
149 has_ssp2_aif2 = true;
150 }
151 if (is_bytcr && !has_ssp0)
152 dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2 on bytcr\n");
153 if (has_ssp0_aif1 && has_ssp0_aif2)
154 dev_err(dev, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n");
155 if (has_ssp0 && has_ssp2_aif2)
156 dev_err(dev, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n");
157
158 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
159 dev_info(dev, "quirk MCLK_EN enabled\n");
160 has_mclk = true;
161 }
162 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
163 if (has_mclk)
164 dev_info(dev, "quirk MCLK_25MHZ enabled\n");
165 else
166 dev_err(dev, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n");
167 }
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500168}
169
Hans de Goedebcd9a322018-05-08 17:35:53 +0200170static int byt_rt5640_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai,
171 int rate)
172{
173 int ret;
174
175 /* Configure the PLL before selecting it */
176 if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) {
177 /* use bitclock as PLL input */
178 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
179 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
180 /* 2x16 bit slots on SSP0 */
181 ret = snd_soc_dai_set_pll(codec_dai, 0,
182 RT5640_PLL1_S_BCLK1,
183 rate * 32, rate * 512);
184 } else {
185 /* 2x15 bit slots on SSP2 */
186 ret = snd_soc_dai_set_pll(codec_dai, 0,
187 RT5640_PLL1_S_BCLK1,
188 rate * 50, rate * 512);
189 }
190 } else {
191 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
192 ret = snd_soc_dai_set_pll(codec_dai, 0,
193 RT5640_PLL1_S_MCLK,
194 25000000, rate * 512);
195 } else {
196 ret = snd_soc_dai_set_pll(codec_dai, 0,
197 RT5640_PLL1_S_MCLK,
198 19200000, rate * 512);
199 }
200 }
201
202 if (ret < 0) {
Hans de Goedea3a956a2018-05-11 11:52:16 +0200203 dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret);
Hans de Goedebcd9a322018-05-08 17:35:53 +0200204 return ret;
205 }
206
207 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
208 rate * 512, SND_SOC_CLOCK_IN);
209 if (ret < 0) {
Hans de Goedea3a956a2018-05-11 11:52:16 +0200210 dev_err(codec_dai->component->dev, "can't set clock %d\n", ret);
Hans de Goedebcd9a322018-05-08 17:35:53 +0200211 return ret;
212 }
213
214 return 0;
215}
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500216
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500217#define BYT_CODEC_DAI1 "rt5640-aif1"
218#define BYT_CODEC_DAI2 "rt5640-aif2"
219
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500220static int platform_clock_control(struct snd_soc_dapm_widget *w,
221 struct snd_kcontrol *k, int event)
222{
223 struct snd_soc_dapm_context *dapm = w->dapm;
224 struct snd_soc_card *card = dapm->card;
225 struct snd_soc_dai *codec_dai;
226 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
227 int ret;
228
Pierre-Louis Bossartdfb6ec72017-10-12 18:38:03 -0500229 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1);
230 if (!codec_dai)
231 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2);
232
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500233 if (!codec_dai) {
234 dev_err(card->dev,
235 "Codec dai not found; Unable to set platform clock\n");
236 return -EIO;
237 }
238
239 if (SND_SOC_DAPM_EVENT_ON(event)) {
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500240 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500241 ret = clk_prepare_enable(priv->mclk);
242 if (ret < 0) {
243 dev_err(card->dev,
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500244 "could not configure MCLK state\n");
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500245 return ret;
246 }
247 }
Hans de Goedebcd9a322018-05-08 17:35:53 +0200248 ret = byt_rt5640_prepare_and_enable_pll1(codec_dai, 48000);
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500249 } else {
250 /*
251 * Set codec clock source to internal clock before
252 * turning off the platform clock. Codec needs clock
253 * for Jack detection and button press
254 */
255 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK,
Pierre-Louis Bossart60448b02017-01-04 15:44:52 -0600256 48000 * 512,
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500257 SND_SOC_CLOCK_IN);
258 if (!ret) {
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500259 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500260 clk_disable_unprepare(priv->mclk);
261 }
262 }
263
264 if (ret < 0) {
265 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
266 return ret;
267 }
268
269 return 0;
270}
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -0600271
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600272static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530273 SND_SOC_DAPM_HP("Headphone", NULL),
274 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600275 SND_SOC_DAPM_MIC("Internal Mic", NULL),
276 SND_SOC_DAPM_SPK("Speaker", NULL),
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500277 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
278 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
279 SND_SOC_DAPM_POST_PMD),
280
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530281};
282
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600283static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500284 {"Headphone", NULL, "Platform Clock"},
285 {"Headset Mic", NULL, "Platform Clock"},
286 {"Internal Mic", NULL, "Platform Clock"},
287 {"Speaker", NULL, "Platform Clock"},
288
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530289 {"Headset Mic", NULL, "MICBIAS1"},
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600290 {"IN2P", NULL, "Headset Mic"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530291 {"Headphone", NULL, "HPOL"},
292 {"Headphone", NULL, "HPOR"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530293};
294
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600295static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
296 {"DMIC1", NULL, "Internal Mic"},
297};
298
299static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
300 {"DMIC2", NULL, "Internal Mic"},
301};
302
303static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
304 {"Internal Mic", NULL, "MICBIAS1"},
305 {"IN1P", NULL, "Internal Mic"},
306};
307
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -0500308static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
309 {"Internal Mic", NULL, "MICBIAS1"},
310 {"IN3P", NULL, "Internal Mic"},
311};
312
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500313static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
314 {"ssp2 Tx", NULL, "codec_out0"},
315 {"ssp2 Tx", NULL, "codec_out1"},
316 {"codec_in0", NULL, "ssp2 Rx"},
317 {"codec_in1", NULL, "ssp2 Rx"},
318
319 {"AIF1 Playback", NULL, "ssp2 Tx"},
320 {"ssp2 Rx", NULL, "AIF1 Capture"},
321};
322
323static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
324 {"ssp2 Tx", NULL, "codec_out0"},
325 {"ssp2 Tx", NULL, "codec_out1"},
326 {"codec_in0", NULL, "ssp2 Rx"},
327 {"codec_in1", NULL, "ssp2 Rx"},
328
329 {"AIF2 Playback", NULL, "ssp2 Tx"},
330 {"ssp2 Rx", NULL, "AIF2 Capture"},
331};
332
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500333static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
334 {"ssp0 Tx", NULL, "modem_out"},
335 {"modem_in", NULL, "ssp0 Rx"},
336
337 {"AIF1 Playback", NULL, "ssp0 Tx"},
338 {"ssp0 Rx", NULL, "AIF1 Capture"},
339};
340
341static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
342 {"ssp0 Tx", NULL, "modem_out"},
343 {"modem_in", NULL, "ssp0 Rx"},
344
345 {"AIF2 Playback", NULL, "ssp0 Tx"},
346 {"ssp0 Rx", NULL, "AIF2 Capture"},
347};
348
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500349static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
350 {"Speaker", NULL, "SPOLP"},
351 {"Speaker", NULL, "SPOLN"},
352 {"Speaker", NULL, "SPORP"},
353 {"Speaker", NULL, "SPORN"},
354};
355
356static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
357 {"Speaker", NULL, "SPOLP"},
358 {"Speaker", NULL, "SPOLN"},
359};
360
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600361static const struct snd_kcontrol_new byt_rt5640_controls[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530362 SOC_DAPM_PIN_SWITCH("Headphone"),
363 SOC_DAPM_PIN_SWITCH("Headset Mic"),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600364 SOC_DAPM_PIN_SWITCH("Internal Mic"),
365 SOC_DAPM_PIN_SWITCH("Speaker"),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530366};
367
Hans de Goede77323102018-05-13 09:24:28 +0200368static struct snd_soc_jack_pin rt5640_pins[] = {
369 {
370 .pin = "Headphone",
371 .mask = SND_JACK_HEADPHONE,
372 },
373 {
374 .pin = "Headset Mic",
375 .mask = SND_JACK_MICROPHONE,
376 },
377};
378
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600379static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530380 struct snd_pcm_hw_params *params)
381{
Kuninori Morimoto2207b932020-07-27 10:08:29 +0900382 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +0900383 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530384
Hans de Goedebcd9a322018-05-08 17:35:53 +0200385 return byt_rt5640_prepare_and_enable_pll1(dai, params_rate(params));
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530386}
387
Hans de Goede3c0d0112018-05-13 09:24:32 +0200388/* Please keep this list alphabetically sorted */
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600389static const struct dmi_system_id byt_rt5640_quirk_table[] = {
Hans de Goedeec8e8412018-05-13 09:24:34 +0200390 { /* Acer Iconia Tab 8 W1-810 */
391 .matches = {
392 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
393 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
394 },
395 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
396 BYT_RT5640_JD_SRC_JD1_IN4P |
Hans de Goedef12a0a32018-06-03 15:42:32 +0200397 BYT_RT5640_OVCD_TH_1500UA |
Hans de Goedeec8e8412018-05-13 09:24:34 +0200398 BYT_RT5640_OVCD_SF_0P75 |
399 BYT_RT5640_SSP0_AIF1 |
400 BYT_RT5640_MCLK_EN),
401 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600402 {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600403 .matches = {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200404 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
405 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
406 },
Hans de Goede0bb88772019-11-19 15:51:38 +0100407 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
408 BYT_RT5640_JD_SRC_JD2_IN4N |
409 BYT_RT5640_OVCD_TH_2000UA |
410 BYT_RT5640_OVCD_SF_0P75 |
411 BYT_RT5640_SSP0_AIF1 |
412 BYT_RT5640_MCLK_EN),
Hans de Goede3c0d0112018-05-13 09:24:32 +0200413 },
414 {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200415 .matches = {
Hans de Goedebcf441a2018-05-28 22:26:49 +0200416 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
417 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 80 Cesium"),
418 },
419 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
420 BYT_RT5640_MONO_SPEAKER |
421 BYT_RT5640_SSP0_AIF1 |
422 BYT_RT5640_MCLK_EN),
423 },
424 {
425 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500426 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
Stephan Gerhold51a13e42019-01-02 20:39:08 +0100427 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
428 },
429 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
430 BYT_RT5640_JD_SRC_JD2_IN4N |
431 BYT_RT5640_OVCD_TH_2000UA |
432 BYT_RT5640_OVCD_SF_0P75 |
433 BYT_RT5640_SSP0_AIF1 |
434 BYT_RT5640_MCLK_EN),
435 },
436 {
437 .matches = {
438 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500439 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600440 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500441 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
Hans de Goede77323102018-05-13 09:24:28 +0200442 BYT_RT5640_JD_SRC_JD2_IN4N |
443 BYT_RT5640_OVCD_TH_2000UA |
444 BYT_RT5640_OVCD_SF_0P75 |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500445 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600446 },
447 {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600448 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500449 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
450 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
451 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500452 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
453 BYT_RT5640_MONO_SPEAKER |
454 BYT_RT5640_DIFF_MIC |
455 BYT_RT5640_SSP0_AIF2 |
456 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500457 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200458 { /* Chuwi Vi8 (CWI506) */
459 .matches = {
460 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"),
461 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "i86"),
462 /* The above are too generic, also match BIOS info */
463 DMI_MATCH(DMI_BIOS_VERSION, "CHUWI.D86JLBNR"),
464 },
465 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
466 BYT_RT5640_MONO_SPEAKER |
467 BYT_RT5640_SSP0_AIF1 |
468 BYT_RT5640_MCLK_EN),
469 },
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500470 {
Hans de Goeded5a18262018-06-08 10:19:25 +0200471 /* Chuwi Vi10 (CWI505) */
472 .matches = {
473 DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
474 DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"),
475 DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
476 DMI_MATCH(DMI_PRODUCT_NAME, "S165"),
477 },
478 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
479 BYT_RT5640_JD_SRC_JD2_IN4N |
480 BYT_RT5640_OVCD_TH_2000UA |
481 BYT_RT5640_OVCD_SF_0P75 |
482 BYT_RT5640_DIFF_MIC |
483 BYT_RT5640_SSP0_AIF1 |
484 BYT_RT5640_MCLK_EN),
485 },
486 {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500487 .matches = {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200488 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
489 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
490 },
491 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP),
492 },
Hans de Goede9ee6f8a2018-07-01 11:30:23 +0200493 { /* Connect Tablet 9 */
494 .matches = {
495 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Connect"),
496 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Tablet 9"),
497 },
498 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
499 BYT_RT5640_MONO_SPEAKER |
500 BYT_RT5640_SSP0_AIF1 |
501 BYT_RT5640_MCLK_EN),
502 },
Hans de Goede3c0d0112018-05-13 09:24:32 +0200503 {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200504 .matches = {
Hans de Goede6748fb72018-05-13 09:24:27 +0200505 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500506 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600507 },
Hans de Goede6748fb72018-05-13 09:24:27 +0200508 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
Hans de Goede77323102018-05-13 09:24:28 +0200509 BYT_RT5640_JD_SRC_JD2_IN4N |
510 BYT_RT5640_OVCD_TH_2000UA |
511 BYT_RT5640_OVCD_SF_0P75 |
Hans de Goede6748fb72018-05-13 09:24:27 +0200512 BYT_RT5640_MONO_SPEAKER |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500513 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600514 },
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600515 {
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600516 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500517 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
518 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600519 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500520 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
521 BYT_RT5640_MCLK_EN),
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600522 },
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100523 { /* HP Pavilion x2 10-k0XX, 10-n0XX */
Hans de Goedeec8e8412018-05-13 09:24:34 +0200524 .matches = {
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100525 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
526 DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion x2 Detachable"),
Hans de Goedeec8e8412018-05-13 09:24:34 +0200527 },
528 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
529 BYT_RT5640_JD_SRC_JD2_IN4N |
530 BYT_RT5640_OVCD_TH_1500UA |
531 BYT_RT5640_OVCD_SF_0P75 |
532 BYT_RT5640_SSP0_AIF1 |
533 BYT_RT5640_MCLK_EN),
534 },
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100535 { /* HP Pavilion x2 10-p0XX */
536 .matches = {
537 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
538 DMI_MATCH(DMI_PRODUCT_NAME, "HP x2 Detachable 10-p0XX"),
539 },
540 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
541 BYT_RT5640_JD_SRC_JD1_IN4P |
542 BYT_RT5640_OVCD_TH_1500UA |
543 BYT_RT5640_OVCD_SF_0P75 |
544 BYT_RT5640_MCLK_EN),
545 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200546 { /* HP Stream 7 */
547 .matches = {
548 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
549 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Stream 7 Tablet"),
550 },
551 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
552 BYT_RT5640_MONO_SPEAKER |
553 BYT_RT5640_JD_NOT_INV |
554 BYT_RT5640_SSP0_AIF1 |
555 BYT_RT5640_MCLK_EN),
556 },
557 { /* I.T.Works TW891 */
558 .matches = {
559 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
560 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
561 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
562 DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
563 },
564 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
565 BYT_RT5640_MONO_SPEAKER |
566 BYT_RT5640_SSP0_AIF1 |
567 BYT_RT5640_MCLK_EN),
568 },
569 { /* Lamina I8270 / T701BR.SE */
570 .matches = {
571 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Lamina"),
572 DMI_EXACT_MATCH(DMI_BOARD_NAME, "T701BR.SE"),
573 },
574 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
575 BYT_RT5640_MONO_SPEAKER |
576 BYT_RT5640_JD_NOT_INV |
577 BYT_RT5640_SSP0_AIF1 |
578 BYT_RT5640_MCLK_EN),
579 },
Hans de Goede81583af2018-07-07 12:22:10 +0200580 { /* Lenovo Miix 2 8 */
581 .matches = {
582 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
583 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "20326"),
584 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Hiking"),
585 },
586 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
587 BYT_RT5640_JD_SRC_JD2_IN4N |
588 BYT_RT5640_OVCD_TH_2000UA |
589 BYT_RT5640_OVCD_SF_0P75 |
590 BYT_RT5640_MONO_SPEAKER |
591 BYT_RT5640_MCLK_EN),
592 },
Hans de Goede260c48b2018-08-12 13:42:06 +0200593 { /* Linx Linx7 tablet */
594 .matches = {
595 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LINX"),
596 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LINX7"),
597 },
598 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
599 BYT_RT5640_MONO_SPEAKER |
600 BYT_RT5640_JD_NOT_INV |
601 BYT_RT5640_SSP0_AIF1 |
602 BYT_RT5640_MCLK_EN),
603 },
Hans de Goede6a013712020-09-01 10:06:23 +0200604 { /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */
605 .matches = {
606 DMI_MATCH(DMI_SYS_VENDOR, "MPMAN"),
607 DMI_MATCH(DMI_PRODUCT_NAME, "Converter9"),
608 },
609 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
610 BYT_RT5640_MONO_SPEAKER |
611 BYT_RT5640_SSP0_AIF1 |
612 BYT_RT5640_MCLK_EN),
613 },
Hans de Goedec8b78f22020-04-05 15:37:26 +0200614 {
615 /* MPMAN MPWIN895CL */
616 .matches = {
617 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MPMAN"),
618 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MPWIN8900CL"),
619 },
620 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
621 BYT_RT5640_MONO_SPEAKER |
622 BYT_RT5640_SSP0_AIF1 |
623 BYT_RT5640_MCLK_EN),
624 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200625 { /* MSI S100 tablet */
626 .matches = {
627 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
628 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "S100"),
629 },
630 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
631 BYT_RT5640_JD_SRC_JD2_IN4N |
632 BYT_RT5640_OVCD_TH_2000UA |
633 BYT_RT5640_OVCD_SF_0P75 |
634 BYT_RT5640_MONO_SPEAKER |
635 BYT_RT5640_DIFF_MIC |
636 BYT_RT5640_MCLK_EN),
637 },
Hans de Goede6cea3592018-06-03 15:42:31 +0200638 { /* Nuvison/TMax TM800W560 */
639 .matches = {
640 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TMAX"),
641 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TM800W560L"),
642 },
643 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
644 BYT_RT5640_JD_SRC_JD2_IN4N |
645 BYT_RT5640_OVCD_TH_2000UA |
646 BYT_RT5640_OVCD_SF_0P75 |
647 BYT_RT5640_JD_NOT_INV |
648 BYT_RT5640_DIFF_MIC |
649 BYT_RT5640_SSP0_AIF1 |
650 BYT_RT5640_MCLK_EN),
651 },
Hans de Goede260c48b2018-08-12 13:42:06 +0200652 { /* Onda v975w */
653 .matches = {
654 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
655 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
656 /* The above are too generic, also match BIOS info */
657 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "5.6.5"),
658 DMI_EXACT_MATCH(DMI_BIOS_DATE, "07/25/2014"),
659 },
660 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
661 BYT_RT5640_JD_SRC_JD2_IN4N |
662 BYT_RT5640_OVCD_TH_2000UA |
663 BYT_RT5640_OVCD_SF_0P75 |
664 BYT_RT5640_DIFF_MIC |
665 BYT_RT5640_MCLK_EN),
666 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200667 { /* Pipo W4 */
668 .matches = {
669 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
670 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
671 /* The above are too generic, also match BIOS info */
672 DMI_MATCH(DMI_BIOS_VERSION, "V8L_WIN32_CHIPHD"),
673 },
674 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
675 BYT_RT5640_MONO_SPEAKER |
676 BYT_RT5640_SSP0_AIF1 |
677 BYT_RT5640_MCLK_EN),
678 },
679 { /* Point of View Mobii TAB-P800W (V2.0) */
680 .matches = {
681 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
682 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
683 /* The above are too generic, also match BIOS info */
684 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1014"),
685 DMI_EXACT_MATCH(DMI_BIOS_DATE, "10/24/2014"),
686 },
687 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
688 BYT_RT5640_JD_SRC_JD2_IN4N |
689 BYT_RT5640_OVCD_TH_2000UA |
690 BYT_RT5640_OVCD_SF_0P75 |
691 BYT_RT5640_MONO_SPEAKER |
692 BYT_RT5640_DIFF_MIC |
693 BYT_RT5640_SSP0_AIF2 |
694 BYT_RT5640_MCLK_EN),
695 },
696 { /* Point of View Mobii TAB-P800W (V2.1) */
697 .matches = {
698 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
699 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
700 /* The above are too generic, also match BIOS info */
701 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1013"),
702 DMI_EXACT_MATCH(DMI_BIOS_DATE, "08/22/2014"),
703 },
704 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
705 BYT_RT5640_JD_SRC_JD2_IN4N |
706 BYT_RT5640_OVCD_TH_2000UA |
707 BYT_RT5640_OVCD_SF_0P75 |
708 BYT_RT5640_MONO_SPEAKER |
709 BYT_RT5640_DIFF_MIC |
710 BYT_RT5640_SSP0_AIF2 |
711 BYT_RT5640_MCLK_EN),
712 },
Hans de Goede02e5af62018-12-08 14:01:14 +0100713 { /* Point of View Mobii TAB-P1005W-232 (V2.0) */
714 .matches = {
715 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "POV"),
716 DMI_EXACT_MATCH(DMI_BOARD_NAME, "I102A"),
717 },
718 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
719 BYT_RT5640_JD_SRC_JD2_IN4N |
720 BYT_RT5640_OVCD_TH_2000UA |
721 BYT_RT5640_OVCD_SF_0P75 |
722 BYT_RT5640_DIFF_MIC |
723 BYT_RT5640_SSP0_AIF1 |
724 BYT_RT5640_MCLK_EN),
725 },
Irina Tirdea0565e772016-08-12 16:27:58 -0500726 {
Hans de Goede271248f2018-12-08 14:01:13 +0100727 /* Prowise PT301 */
728 .matches = {
729 DMI_MATCH(DMI_SYS_VENDOR, "Prowise"),
730 DMI_MATCH(DMI_PRODUCT_NAME, "PT301"),
731 },
732 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
733 BYT_RT5640_JD_SRC_JD2_IN4N |
734 BYT_RT5640_OVCD_TH_2000UA |
735 BYT_RT5640_OVCD_SF_0P75 |
736 BYT_RT5640_DIFF_MIC |
737 BYT_RT5640_SSP0_AIF1 |
738 BYT_RT5640_MCLK_EN),
739 },
740 {
Hans de Goede7eccc052019-12-03 23:14:42 +0100741 /* Teclast X89 */
Irina Tirdea0565e772016-08-12 16:27:58 -0500742 .matches = {
Pierre-Louis Bossartec1c90e2016-08-12 16:27:59 -0500743 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
744 DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
745 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500746 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
Hans de Goede7eccc052019-12-03 23:14:42 +0100747 BYT_RT5640_JD_SRC_JD1_IN4P |
748 BYT_RT5640_OVCD_TH_2000UA |
749 BYT_RT5640_OVCD_SF_1P0 |
750 BYT_RT5640_SSP0_AIF1 |
751 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossartec1c90e2016-08-12 16:27:59 -0500752 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200753 { /* Toshiba Satellite Click Mini L9W-B */
754 .matches = {
755 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
756 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
757 },
758 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
759 BYT_RT5640_JD_SRC_JD2_IN4N |
760 BYT_RT5640_OVCD_TH_1500UA |
761 BYT_RT5640_OVCD_SF_0P75 |
762 BYT_RT5640_SSP0_AIF1 |
763 BYT_RT5640_MCLK_EN),
764 },
Hans de Goede0e0e10f2020-05-18 09:24:16 +0200765 { /* Toshiba Encore WT8-A */
766 .matches = {
767 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
768 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"),
769 },
770 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
771 BYT_RT5640_JD_SRC_JD2_IN4N |
772 BYT_RT5640_OVCD_TH_2000UA |
773 BYT_RT5640_OVCD_SF_0P75 |
774 BYT_RT5640_JD_NOT_INV |
775 BYT_RT5640_MCLK_EN),
776 },
Hans de Goede199a5e82020-06-08 22:46:33 +0200777 { /* Toshiba Encore WT10-A */
778 .matches = {
779 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
780 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"),
781 },
782 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
783 BYT_RT5640_JD_SRC_JD1_IN4P |
784 BYT_RT5640_OVCD_TH_2000UA |
785 BYT_RT5640_OVCD_SF_0P75 |
786 BYT_RT5640_SSP0_AIF2 |
787 BYT_RT5640_MCLK_EN),
788 },
Hans de Goede3c0d0112018-05-13 09:24:32 +0200789 { /* Catch-all for generic Insyde tablets, must be last */
youling25757180042017-01-04 15:44:53 -0600790 .matches = {
791 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
792 },
Hans de Goede96a388fe2018-05-13 09:24:30 +0200793 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500794 BYT_RT5640_MCLK_EN |
795 BYT_RT5640_SSP0_AIF1),
youling25757180042017-01-04 15:44:53 -0600796
797 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600798 {}
799};
800
Hans de Goede6a7c05e2018-05-08 17:35:54 +0200801/*
802 * Note this MUST be called before snd_soc_register_card(), so that the props
803 * are in place before the codec component driver's probe function parses them.
804 */
805static int byt_rt5640_add_codec_device_props(const char *i2c_dev_name)
806{
807 struct property_entry props[MAX_NO_PROPS] = {};
808 struct device *i2c_dev;
809 int ret, cnt = 0;
810
811 i2c_dev = bus_find_device_by_name(&i2c_bus_type, NULL, i2c_dev_name);
812 if (!i2c_dev)
813 return -EPROBE_DEFER;
814
815 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
Hans de Goedea3ad2912018-05-13 09:24:26 +0200816 case BYT_RT5640_DMIC1_MAP:
817 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin",
818 RT5640_DMIC1_DATA_PIN_IN1P);
819 break;
820 case BYT_RT5640_DMIC2_MAP:
821 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin",
822 RT5640_DMIC2_DATA_PIN_IN1N);
823 break;
Hans de Goede6a7c05e2018-05-08 17:35:54 +0200824 case BYT_RT5640_IN1_MAP:
825 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
826 props[cnt++] =
827 PROPERTY_ENTRY_BOOL("realtek,in1-differential");
828 break;
829 case BYT_RT5640_IN3_MAP:
830 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
831 props[cnt++] =
832 PROPERTY_ENTRY_BOOL("realtek,in3-differential");
833 break;
834 }
835
Hans de Goede77323102018-05-13 09:24:28 +0200836 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
837 props[cnt++] = PROPERTY_ENTRY_U32(
838 "realtek,jack-detect-source",
839 BYT_RT5640_JDSRC(byt_rt5640_quirk));
840
841 props[cnt++] = PROPERTY_ENTRY_U32(
842 "realtek,over-current-threshold-microamp",
843 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
844
845 props[cnt++] = PROPERTY_ENTRY_U32(
846 "realtek,over-current-scale-factor",
847 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
848 }
849
850 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
851 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted");
852
Hans de Goede6a7c05e2018-05-08 17:35:54 +0200853 ret = device_add_properties(i2c_dev, props);
854 put_device(i2c_dev);
855
856 return ret;
857}
858
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600859static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
860{
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600861 struct snd_soc_card *card = runtime->card;
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500862 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +0900863 struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500864 const struct snd_soc_dapm_route *custom_map;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600865 int num_routes;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500866 int ret;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600867
868 card->dapm.idle_bias_off = true;
869
Hans de Goede77323102018-05-13 09:24:28 +0200870 /* Start with RC clk for jack-detect (we disable MCLK below) */
871 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
872 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
873 RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_RCCLK);
874
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000875 rt5640_sel_asrc_clk_src(component,
Pierre-Louis Bossart0ec66e2d2016-01-04 17:20:27 -0600876 RT5640_DA_STEREO_FILTER |
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500877 RT5640_DA_MONO_L_FILTER |
878 RT5640_DA_MONO_R_FILTER |
879 RT5640_AD_STEREO_FILTER |
880 RT5640_AD_MONO_L_FILTER |
881 RT5640_AD_MONO_R_FILTER,
Pierre-Louis Bossart0ec66e2d2016-01-04 17:20:27 -0600882 RT5640_CLK_SEL_ASRC);
883
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600884 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
885 ARRAY_SIZE(byt_rt5640_controls));
886 if (ret) {
887 dev_err(card->dev, "unable to add card controls\n");
888 return ret;
889 }
890
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600891 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
892 case BYT_RT5640_IN1_MAP:
893 custom_map = byt_rt5640_intmic_in1_map;
894 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
895 break;
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -0500896 case BYT_RT5640_IN3_MAP:
897 custom_map = byt_rt5640_intmic_in3_map;
898 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
899 break;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600900 case BYT_RT5640_DMIC2_MAP:
901 custom_map = byt_rt5640_intmic_dmic2_map;
902 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
903 break;
904 default:
905 custom_map = byt_rt5640_intmic_dmic1_map;
906 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
907 }
908
909 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
910 if (ret)
911 return ret;
912
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500913 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
914 ret = snd_soc_dapm_add_routes(&card->dapm,
915 byt_rt5640_ssp2_aif2_map,
916 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500917 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
918 ret = snd_soc_dapm_add_routes(&card->dapm,
919 byt_rt5640_ssp0_aif1_map,
920 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
921 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
922 ret = snd_soc_dapm_add_routes(&card->dapm,
923 byt_rt5640_ssp0_aif2_map,
924 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500925 } else {
926 ret = snd_soc_dapm_add_routes(&card->dapm,
927 byt_rt5640_ssp2_aif1_map,
928 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
929 }
930 if (ret)
931 return ret;
932
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500933 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
934 ret = snd_soc_dapm_add_routes(&card->dapm,
935 byt_rt5640_mono_spk_map,
936 ARRAY_SIZE(byt_rt5640_mono_spk_map));
937 } else {
938 ret = snd_soc_dapm_add_routes(&card->dapm,
939 byt_rt5640_stereo_spk_map,
940 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
941 }
942 if (ret)
943 return ret;
944
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500945 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500946 /*
947 * The firmware might enable the clock at
948 * boot (this information may or may not
949 * be reflected in the enable clock register).
950 * To change the rate we must disable the clock
951 * first to cover these cases. Due to common
952 * clock framework restrictions that do not allow
953 * to disable a clock that has not been enabled,
954 * we need to enable the clock first.
955 */
956 ret = clk_prepare_enable(priv->mclk);
957 if (!ret)
958 clk_disable_unprepare(priv->mclk);
959
960 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
961 ret = clk_set_rate(priv->mclk, 25000000);
962 else
963 ret = clk_set_rate(priv->mclk, 19200000);
964
Hans de Goede77323102018-05-13 09:24:28 +0200965 if (ret) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500966 dev_err(card->dev, "unable to set MCLK rate\n");
Hans de Goede77323102018-05-13 09:24:28 +0200967 return ret;
968 }
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500969 }
970
Hans de Goede77323102018-05-13 09:24:28 +0200971 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
972 ret = snd_soc_card_jack_new(card, "Headset",
973 SND_JACK_HEADSET | SND_JACK_BTN_0,
974 &priv->jack, rt5640_pins,
975 ARRAY_SIZE(rt5640_pins));
976 if (ret) {
977 dev_err(card->dev, "Jack creation failed %d\n", ret);
978 return ret;
979 }
980 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
981 KEY_PLAYPAUSE);
982 snd_soc_component_set_jack(component, &priv->jack, NULL);
983 }
984
985 return 0;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600986}
987
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600988static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530989 struct snd_pcm_hw_params *params)
990{
991 struct snd_interval *rate = hw_param_interval(params,
992 SNDRV_PCM_HW_PARAM_RATE);
993 struct snd_interval *channels = hw_param_interval(params,
994 SNDRV_PCM_HW_PARAM_CHANNELS);
Erik Bussing332719b2020-01-15 17:46:16 +0100995 int ret, bits;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530996
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -0500997 /* The DSP will covert the FE rate to 48k, stereo */
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530998 rate->min = rate->max = 48000;
999 channels->min = channels->max = 2;
1000
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001001 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
Erik Bussing332719b2020-01-15 17:46:16 +01001002 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
Pierre-Louis Bossart8f98307d2016-08-16 18:28:22 -05001003 /* set SSP0 to 16-bit */
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001004 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
Erik Bussing332719b2020-01-15 17:46:16 +01001005 bits = 16;
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001006 } else {
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001007 /* set SSP2 to 24-bit */
1008 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
Erik Bussing332719b2020-01-15 17:46:16 +01001009 bits = 24;
Sebastien Guiriec3f27ded2015-12-17 20:35:39 -06001010 }
Erik Bussing332719b2020-01-15 17:46:16 +01001011
1012 /*
1013 * Default mode for SSP configuration is TDM 4 slot, override config
1014 * with explicit setting to I2S 2ch. The word length is set with
1015 * dai_set_tdm_slot() since there is no other API exposed
1016 */
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +09001017 ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
Erik Bussing332719b2020-01-15 17:46:16 +01001018 SND_SOC_DAIFMT_I2S |
1019 SND_SOC_DAIFMT_NB_NF |
1020 SND_SOC_DAIFMT_CBS_CFS);
1021 if (ret < 0) {
1022 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
1023 return ret;
1024 }
1025
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +09001026 ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);
Erik Bussing332719b2020-01-15 17:46:16 +01001027 if (ret < 0) {
1028 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
1029 return ret;
1030 }
1031
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301032 return 0;
1033}
1034
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001035static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301036{
Lars-Peter Clausend0a1b662015-10-18 15:39:30 +02001037 return snd_pcm_hw_constraint_single(substream->runtime,
1038 SNDRV_PCM_HW_PARAM_RATE, 48000);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301039}
1040
Julia Lawall9b6fdef2016-10-15 16:55:49 +02001041static const struct snd_soc_ops byt_rt5640_aif1_ops = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001042 .startup = byt_rt5640_aif1_startup,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301043};
1044
Julia Lawall9b6fdef2016-10-15 16:55:49 +02001045static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001046 .hw_params = byt_rt5640_aif1_hw_params,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301047};
1048
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001049SND_SOC_DAILINK_DEF(dummy,
1050 DAILINK_COMP_ARRAY(COMP_DUMMY()));
1051
1052SND_SOC_DAILINK_DEF(media,
1053 DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
1054
1055SND_SOC_DAILINK_DEF(deepbuffer,
1056 DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
1057
1058SND_SOC_DAILINK_DEF(ssp2_port,
1059 /* overwritten for ssp0 routing */
1060 DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
1061SND_SOC_DAILINK_DEF(ssp2_codec,
1062 DAILINK_COMP_ARRAY(COMP_CODEC(
1063 /* overwritten with HID */ "i2c-10EC5640:00",
1064 /* changed w/ quirk */ "rt5640-aif1")));
1065
1066SND_SOC_DAILINK_DEF(platform,
1067 DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
1068
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001069static struct snd_soc_dai_link byt_rt5640_dais[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301070 [MERR_DPCM_AUDIO] = {
1071 .name = "Baytrail Audio Port",
1072 .stream_name = "Baytrail Audio",
Takashi Iwai6e4cac22017-04-24 14:09:55 +02001073 .nonatomic = true,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301074 .dynamic = 1,
1075 .dpcm_playback = 1,
1076 .dpcm_capture = 1,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001077 .ops = &byt_rt5640_aif1_ops,
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001078 SND_SOC_DAILINK_REG(media, dummy, platform),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301079 },
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001080 [MERR_DPCM_DEEP_BUFFER] = {
1081 .name = "Deep-Buffer Audio Port",
1082 .stream_name = "Deep-Buffer Audio",
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001083 .nonatomic = true,
1084 .dynamic = 1,
1085 .dpcm_playback = 1,
1086 .ops = &byt_rt5640_aif1_ops,
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001087 SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001088 },
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301089 /* back ends */
1090 {
1091 .name = "SSP2-Codec",
Pierre-Louis Bossart149f7752017-10-12 18:38:04 -05001092 .id = 0,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301093 .no_pcm = 1,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301094 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
1095 | SND_SOC_DAIFMT_CBS_CFS,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001096 .be_hw_params_fixup = byt_rt5640_codec_fixup,
Takashi Iwai6e4cac22017-04-24 14:09:55 +02001097 .nonatomic = true,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301098 .dpcm_playback = 1,
1099 .dpcm_capture = 1,
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001100 .init = byt_rt5640_init,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001101 .ops = &byt_rt5640_be_ssp2_ops,
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001102 SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301103 },
1104};
1105
1106/* SoC card */
Hans de Goede77323102018-05-13 09:24:28 +02001107static char byt_rt5640_codec_name[SND_ACPI_I2C_ID_LEN];
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001108#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
Hans de Goede063422c2018-05-13 09:24:35 +02001109static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001110#endif
Jaroslav Kysela0d5c8182019-12-04 15:15:45 -06001111static char byt_rt5640_components[32]; /* = "cfg-spk:* cfg-mic:*" */
Hans de Goede77323102018-05-13 09:24:28 +02001112
1113static int byt_rt5640_suspend(struct snd_soc_card *card)
1114{
1115 struct snd_soc_component *component;
1116
1117 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1118 return 0;
1119
Kuninori Morimotof70f18f72018-09-18 01:29:55 +00001120 for_each_card_components(card, component) {
Hans de Goede77323102018-05-13 09:24:28 +02001121 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1122 dev_dbg(component->dev, "disabling jack detect before suspend\n");
1123 snd_soc_component_set_jack(component, NULL, NULL);
1124 break;
1125 }
1126 }
1127
1128 return 0;
1129}
1130
1131static int byt_rt5640_resume(struct snd_soc_card *card)
1132{
1133 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1134 struct snd_soc_component *component;
1135
1136 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1137 return 0;
1138
Kuninori Morimotof70f18f72018-09-18 01:29:55 +00001139 for_each_card_components(card, component) {
Hans de Goede77323102018-05-13 09:24:28 +02001140 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1141 dev_dbg(component->dev, "re-enabling jack detect after resume\n");
1142 snd_soc_component_set_jack(component, &priv->jack, NULL);
1143 break;
1144 }
1145 }
1146
1147 return 0;
1148}
1149
Pierre-Louis Bossartb4ecd582020-06-17 11:56:14 -05001150#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
1151/* use space before codec name to simplify card ID, and simplify driver name */
1152#define CARD_NAME "bytcht rt5640" /* card name will be 'sof-bytcht rt5640' */
1153#define DRIVER_NAME "SOF"
1154#else
1155#define CARD_NAME "bytcr-rt5640"
1156#define DRIVER_NAME NULL /* card name will be used for driver name */
1157#endif
1158
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001159static struct snd_soc_card byt_rt5640_card = {
Pierre-Louis Bossartb4ecd582020-06-17 11:56:14 -05001160 .name = CARD_NAME,
1161 .driver_name = DRIVER_NAME,
Axel Lin54d86972015-08-21 20:59:21 +08001162 .owner = THIS_MODULE,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001163 .dai_link = byt_rt5640_dais,
1164 .num_links = ARRAY_SIZE(byt_rt5640_dais),
1165 .dapm_widgets = byt_rt5640_widgets,
1166 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
1167 .dapm_routes = byt_rt5640_audio_map,
1168 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001169 .fully_routed = true,
Hans de Goede77323102018-05-13 09:24:28 +02001170 .suspend_pre = byt_rt5640_suspend,
1171 .resume_post = byt_rt5640_resume,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301172};
1173
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001174struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
1175 u64 aif_value; /* 1: AIF1, 2: AIF2 */
1176 u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
1177};
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001178
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001179static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301180{
Colin Ian King4ffdca62019-01-24 17:37:35 +00001181 static const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3" };
Hans de Goede6d1bfcc2018-05-13 09:24:33 +02001182 const struct dmi_system_id *dmi_id;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001183 struct byt_rt5640_private *priv;
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001184 struct snd_soc_acpi_mach *mach;
Pierre-Louis Bossartbd7661b2019-01-25 14:34:59 -06001185 const char *platform_name;
Andy Shevchenkoa320d892019-03-28 19:17:25 +02001186 struct acpi_device *adev;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001187 int ret_val = 0;
Pierre-Louis Bossart2193eb92017-10-12 18:38:05 -05001188 int dai_index = 0;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001189 int i;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001190
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -05001191 is_bytcr = false;
Jia-Ju Bai7a3a6322018-04-09 18:47:37 +08001192 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001193 if (!priv)
1194 return -ENOMEM;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301195
1196 /* register the soc card */
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001197 byt_rt5640_card.dev = &pdev->dev;
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001198 mach = byt_rt5640_card.dev->platform_data;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001199 snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001200
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001201 /* fix index of codec dai */
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001202 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001203 if (!strcmp(byt_rt5640_dais[i].codecs->name,
1204 "i2c-10EC5640:00")) {
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001205 dai_index = i;
1206 break;
1207 }
1208 }
1209
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001210 /* fixup codec name based on HID */
Andy Shevchenkoa320d892019-03-28 19:17:25 +02001211 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
1212 if (adev) {
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001213 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
Andy Shevchenkoa320d892019-03-28 19:17:25 +02001214 "i2c-%s", acpi_dev_name(adev));
1215 put_device(&adev->dev);
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001216 byt_rt5640_dais[dai_index].codecs->name = byt_rt5640_codec_name;
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001217 }
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301218
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001219 /*
1220 * swap SSP0 if bytcr is detected
1221 * (will be overridden if DMI quirk is detected)
1222 */
Pierre-Louis Bossart536cfd22019-05-30 06:50:11 -05001223 if (soc_intel_is_byt()) {
Pierre-Louis Bossart3ee1cd42018-11-01 16:34:50 -05001224 if (mach->mach_params.acpi_ipc_irq_index == 0)
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001225 is_bytcr = true;
1226 }
1227
1228 if (is_bytcr) {
1229 /*
1230 * Baytrail CR platforms may have CHAN package in BIOS, try
1231 * to find relevant routing quirk based as done on Windows
1232 * platforms. We have to read the information directly from the
1233 * BIOS, at this stage the card is not created and the links
1234 * with the codec driver/pdata are non-existent
1235 */
1236
1237 struct acpi_chan_package chan_package;
1238
1239 /* format specified: 2 64-bit integers */
1240 struct acpi_buffer format = {sizeof("NN"), "NN"};
1241 struct acpi_buffer state = {0, NULL};
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001242 struct snd_soc_acpi_package_context pkg_ctx;
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001243 bool pkg_found = false;
1244
1245 state.length = sizeof(chan_package);
1246 state.pointer = &chan_package;
1247
1248 pkg_ctx.name = "CHAN";
1249 pkg_ctx.length = 2;
1250 pkg_ctx.format = &format;
1251 pkg_ctx.state = &state;
1252 pkg_ctx.data_valid = false;
1253
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001254 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
1255 &pkg_ctx);
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001256 if (pkg_found) {
1257 if (chan_package.aif_value == 1) {
1258 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
1259 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
1260 } else if (chan_package.aif_value == 2) {
1261 dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n");
1262 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1263 } else {
1264 dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n");
1265 pkg_found = false;
1266 }
1267 }
1268
1269 if (!pkg_found) {
1270 /* no BIOS indications, assume SSP0-AIF2 connection */
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001271 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1272 }
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -06001273
1274 /* change defaults for Baytrail-CR capture */
Hans de Goede96a388fe2018-05-13 09:24:30 +02001275 byt_rt5640_quirk |= BYTCR_INPUT_DEFAULTS;
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -06001276 } else {
Hans de Goede56ff4402018-05-13 09:24:31 +02001277 byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP |
1278 BYT_RT5640_JD_SRC_JD2_IN4N |
1279 BYT_RT5640_OVCD_TH_2000UA |
1280 BYT_RT5640_OVCD_SF_0P75;
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001281 }
1282
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -06001283 /* check quirks before creating card */
Hans de Goede6d1bfcc2018-05-13 09:24:33 +02001284 dmi_id = dmi_first_match(byt_rt5640_quirk_table);
1285 if (dmi_id)
1286 byt_rt5640_quirk = (unsigned long)dmi_id->driver_data;
Pierre-Louis Bossart2fb2a192019-04-19 15:12:17 -05001287 if (quirk_override != -1) {
Pierre-Louis Bossart2697f3a2020-06-25 14:12:57 -05001288 dev_info(&pdev->dev, "Overriding quirk 0x%lx => 0x%x\n",
1289 byt_rt5640_quirk, quirk_override);
Takashi Iwai9f2cf732017-04-23 09:22:56 +02001290 byt_rt5640_quirk = quirk_override;
1291 }
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001292
1293 /* Must be called before register_card, also see declaration comment. */
1294 ret_val = byt_rt5640_add_codec_device_props(byt_rt5640_codec_name);
1295 if (ret_val)
1296 return ret_val;
1297
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -05001298 log_quirks(&pdev->dev);
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -06001299
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001300 if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
Nariman Etemadi29686832020-01-15 17:46:17 +01001301 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2))
1302 byt_rt5640_dais[dai_index].codecs->dai_name = "rt5640-aif2";
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -05001303
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001304 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
Nariman Etemadi29686832020-01-15 17:46:17 +01001305 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2))
1306 byt_rt5640_dais[dai_index].cpus->dai_name = "ssp0-port";
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001307
Pierre-Louis Bossart7735bce2017-09-08 12:43:52 -05001308 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001309 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
1310 if (IS_ERR(priv->mclk)) {
Pierre-Louis Bossart4a8b3a62016-12-16 10:55:49 -06001311 ret_val = PTR_ERR(priv->mclk);
1312
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001313 dev_err(&pdev->dev,
Pierre-Louis Bossart4a8b3a62016-12-16 10:55:49 -06001314 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
1315 ret_val);
1316
1317 /*
1318 * Fall back to bit clock usage for -ENOENT (clock not
1319 * available likely due to missing dependencies), bail
1320 * for all other errors, including -EPROBE_DEFER
1321 */
1322 if (ret_val != -ENOENT)
1323 return ret_val;
1324 byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001325 }
1326 }
1327
Jaroslav Kysela0d5c8182019-12-04 15:15:45 -06001328 snprintf(byt_rt5640_components, sizeof(byt_rt5640_components),
1329 "cfg-spk:%s cfg-mic:%s",
1330 (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) ? "1" : "2",
1331 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1332 byt_rt5640_card.components = byt_rt5640_components;
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001333#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
Hans de Goede063422c2018-05-13 09:24:35 +02001334 snprintf(byt_rt5640_long_name, sizeof(byt_rt5640_long_name),
1335 "bytcr-rt5640-%s-spk-%s-mic",
1336 (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) ?
1337 "mono" : "stereo",
1338 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1339 byt_rt5640_card.long_name = byt_rt5640_long_name;
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001340#endif
Hans de Goede063422c2018-05-13 09:24:35 +02001341
Pierre-Louis Bossartbd7661b2019-01-25 14:34:59 -06001342 /* override plaform name, if required */
1343 platform_name = mach->mach_params.platform;
1344
1345 ret_val = snd_soc_fixup_dai_links_platform_name(&byt_rt5640_card,
1346 platform_name);
1347 if (ret_val)
1348 return ret_val;
1349
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001350 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
1351
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301352 if (ret_val) {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001353 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
1354 ret_val);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301355 return ret_val;
1356 }
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001357 platform_set_drvdata(pdev, &byt_rt5640_card);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301358 return ret_val;
1359}
1360
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001361static struct platform_driver snd_byt_rt5640_mc_driver = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301362 .driver = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001363 .name = "bytcr_rt5640",
Pierre-Louis Bossart68224372020-05-26 15:36:36 -05001364#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
1365 .pm = &snd_soc_pm_ops,
1366#endif
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301367 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001368 .probe = snd_byt_rt5640_mc_probe,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301369};
1370
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001371module_platform_driver(snd_byt_rt5640_mc_driver);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301372
1373MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
1374MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
1375MODULE_LICENSE("GPL v2");
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001376MODULE_ALIAS("platform:bytcr_rt5640");