blob: a81820943de6795fb3569345dc8c13894de5d2f7 [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,
Hans de Goede46466ab2021-01-09 22:01:18 +010038 BYT_RT5640_NO_INTERNAL_MIC_MAP,
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060039};
40
Hans de Goede77323102018-05-13 09:24:28 +020041enum {
42 BYT_RT5640_JD_SRC_GPIO1 = (RT5640_JD_SRC_GPIO1 << 4),
43 BYT_RT5640_JD_SRC_JD1_IN4P = (RT5640_JD_SRC_JD1_IN4P << 4),
44 BYT_RT5640_JD_SRC_JD2_IN4N = (RT5640_JD_SRC_JD2_IN4N << 4),
45 BYT_RT5640_JD_SRC_GPIO2 = (RT5640_JD_SRC_GPIO2 << 4),
46 BYT_RT5640_JD_SRC_GPIO3 = (RT5640_JD_SRC_GPIO3 << 4),
47 BYT_RT5640_JD_SRC_GPIO4 = (RT5640_JD_SRC_GPIO4 << 4),
48};
Irina Tirdeadf1a2772016-08-12 16:27:57 -050049
Hans de Goede77323102018-05-13 09:24:28 +020050enum {
51 BYT_RT5640_OVCD_TH_600UA = (6 << 8),
52 BYT_RT5640_OVCD_TH_1500UA = (15 << 8),
53 BYT_RT5640_OVCD_TH_2000UA = (20 << 8),
54};
55
56enum {
57 BYT_RT5640_OVCD_SF_0P5 = (RT5640_OVCD_SF_0P5 << 13),
58 BYT_RT5640_OVCD_SF_0P75 = (RT5640_OVCD_SF_0P75 << 13),
59 BYT_RT5640_OVCD_SF_1P0 = (RT5640_OVCD_SF_1P0 << 13),
60 BYT_RT5640_OVCD_SF_1P5 = (RT5640_OVCD_SF_1P5 << 13),
61};
62
63#define BYT_RT5640_MAP(quirk) ((quirk) & GENMASK(3, 0))
64#define BYT_RT5640_JDSRC(quirk) (((quirk) & GENMASK(7, 4)) >> 4)
65#define BYT_RT5640_OVCD_TH(quirk) (((quirk) & GENMASK(12, 8)) >> 8)
66#define BYT_RT5640_OVCD_SF(quirk) (((quirk) & GENMASK(14, 13)) >> 13)
67#define BYT_RT5640_JD_NOT_INV BIT(16)
68#define BYT_RT5640_MONO_SPEAKER BIT(17)
69#define BYT_RT5640_DIFF_MIC BIT(18) /* default is single-ended */
70#define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */
71#define BYT_RT5640_SSP0_AIF1 BIT(20)
72#define BYT_RT5640_SSP0_AIF2 BIT(21)
73#define BYT_RT5640_MCLK_EN BIT(22)
74#define BYT_RT5640_MCLK_25MHZ BIT(23)
Hans de Goede1851ccf2021-01-09 22:01:17 +010075#define BYT_RT5640_NO_SPEAKERS BIT(24)
Hans de Goede77323102018-05-13 09:24:28 +020076
Hans de Goede96a388fe2018-05-13 09:24:30 +020077#define BYTCR_INPUT_DEFAULTS \
78 (BYT_RT5640_IN3_MAP | \
Hans de Goede56ff4402018-05-13 09:24:31 +020079 BYT_RT5640_JD_SRC_JD1_IN4P | \
80 BYT_RT5640_OVCD_TH_2000UA | \
81 BYT_RT5640_OVCD_SF_0P75 | \
Hans de Goede96a388fe2018-05-13 09:24:30 +020082 BYT_RT5640_DIFF_MIC)
83
Hans de Goede77323102018-05-13 09:24:28 +020084/* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
85#define MAX_NO_PROPS 6
Hans de Goede6a7c05e2018-05-08 17:35:54 +020086
Irina Tirdeadf1a2772016-08-12 16:27:57 -050087struct byt_rt5640_private {
Hans de Goede77323102018-05-13 09:24:28 +020088 struct snd_soc_jack jack;
Irina Tirdeadf1a2772016-08-12 16:27:57 -050089 struct clk *mclk;
90};
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -050091static bool is_bytcr;
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060092
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -060093static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN;
Pierre-Louis Bossart2fb2a192019-04-19 15:12:17 -050094static int quirk_override = -1;
95module_param_named(quirk, quirk_override, int, 0444);
Takashi Iwai9f2cf732017-04-23 09:22:56 +020096MODULE_PARM_DESC(quirk, "Board-specific quirk override");
Irina Tirdeadf1a2772016-08-12 16:27:57 -050097
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -050098static void log_quirks(struct device *dev)
99{
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500100 int map;
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500101 bool has_mclk = false;
102 bool has_ssp0 = false;
103 bool has_ssp0_aif1 = false;
104 bool has_ssp0_aif2 = false;
105 bool has_ssp2_aif2 = false;
106
107 map = BYT_RT5640_MAP(byt_rt5640_quirk);
108 switch (map) {
109 case BYT_RT5640_DMIC1_MAP:
110 dev_info(dev, "quirk DMIC1_MAP enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500111 break;
112 case BYT_RT5640_DMIC2_MAP:
113 dev_info(dev, "quirk DMIC2_MAP enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500114 break;
115 case BYT_RT5640_IN1_MAP:
116 dev_info(dev, "quirk IN1_MAP enabled\n");
117 break;
118 case BYT_RT5640_IN3_MAP:
119 dev_info(dev, "quirk IN3_MAP enabled\n");
120 break;
Hans de Goede46466ab2021-01-09 22:01:18 +0100121 case BYT_RT5640_NO_INTERNAL_MIC_MAP:
122 dev_info(dev, "quirk NO_INTERNAL_MIC_MAP enabled\n");
123 break;
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500124 default:
125 dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
126 break;
127 }
Hans de Goede77323102018-05-13 09:24:28 +0200128 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
129 dev_info(dev, "quirk realtek,jack-detect-source %ld\n",
130 BYT_RT5640_JDSRC(byt_rt5640_quirk));
131 dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n",
132 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
133 dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n",
134 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
135 }
136 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
137 dev_info(dev, "quirk JD_NOT_INV enabled\n");
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500138 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500139 dev_info(dev, "quirk MONO_SPEAKER enabled\n");
Hans de Goede1851ccf2021-01-09 22:01:17 +0100140 if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)
141 dev_info(dev, "quirk NO_SPEAKERS enabled\n");
Hans de Goedea3ad2912018-05-13 09:24:26 +0200142 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
143 dev_info(dev, "quirk DIFF_MIC enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500144 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
145 dev_info(dev, "quirk SSP0_AIF1 enabled\n");
146 has_ssp0 = true;
147 has_ssp0_aif1 = true;
148 }
149 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
150 dev_info(dev, "quirk SSP0_AIF2 enabled\n");
151 has_ssp0 = true;
152 has_ssp0_aif2 = true;
153 }
154 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
155 dev_info(dev, "quirk SSP2_AIF2 enabled\n");
156 has_ssp2_aif2 = true;
157 }
158 if (is_bytcr && !has_ssp0)
159 dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2 on bytcr\n");
160 if (has_ssp0_aif1 && has_ssp0_aif2)
161 dev_err(dev, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n");
162 if (has_ssp0 && has_ssp2_aif2)
163 dev_err(dev, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n");
164
165 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
166 dev_info(dev, "quirk MCLK_EN enabled\n");
167 has_mclk = true;
168 }
169 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
170 if (has_mclk)
171 dev_info(dev, "quirk MCLK_25MHZ enabled\n");
172 else
173 dev_err(dev, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n");
174 }
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500175}
176
Hans de Goedebcd9a322018-05-08 17:35:53 +0200177static int byt_rt5640_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai,
178 int rate)
179{
180 int ret;
181
182 /* Configure the PLL before selecting it */
183 if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) {
184 /* use bitclock as PLL input */
185 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
186 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
187 /* 2x16 bit slots on SSP0 */
188 ret = snd_soc_dai_set_pll(codec_dai, 0,
189 RT5640_PLL1_S_BCLK1,
190 rate * 32, rate * 512);
191 } else {
192 /* 2x15 bit slots on SSP2 */
193 ret = snd_soc_dai_set_pll(codec_dai, 0,
194 RT5640_PLL1_S_BCLK1,
195 rate * 50, rate * 512);
196 }
197 } else {
198 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
199 ret = snd_soc_dai_set_pll(codec_dai, 0,
200 RT5640_PLL1_S_MCLK,
201 25000000, rate * 512);
202 } else {
203 ret = snd_soc_dai_set_pll(codec_dai, 0,
204 RT5640_PLL1_S_MCLK,
205 19200000, rate * 512);
206 }
207 }
208
209 if (ret < 0) {
Hans de Goedea3a956a2018-05-11 11:52:16 +0200210 dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret);
Hans de Goedebcd9a322018-05-08 17:35:53 +0200211 return ret;
212 }
213
214 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
215 rate * 512, SND_SOC_CLOCK_IN);
216 if (ret < 0) {
Hans de Goedea3a956a2018-05-11 11:52:16 +0200217 dev_err(codec_dai->component->dev, "can't set clock %d\n", ret);
Hans de Goedebcd9a322018-05-08 17:35:53 +0200218 return ret;
219 }
220
221 return 0;
222}
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500223
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500224#define BYT_CODEC_DAI1 "rt5640-aif1"
225#define BYT_CODEC_DAI2 "rt5640-aif2"
226
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500227static int platform_clock_control(struct snd_soc_dapm_widget *w,
228 struct snd_kcontrol *k, int event)
229{
230 struct snd_soc_dapm_context *dapm = w->dapm;
231 struct snd_soc_card *card = dapm->card;
232 struct snd_soc_dai *codec_dai;
233 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
234 int ret;
235
Pierre-Louis Bossartdfb6ec72017-10-12 18:38:03 -0500236 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1);
237 if (!codec_dai)
238 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2);
239
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500240 if (!codec_dai) {
241 dev_err(card->dev,
242 "Codec dai not found; Unable to set platform clock\n");
243 return -EIO;
244 }
245
246 if (SND_SOC_DAPM_EVENT_ON(event)) {
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500247 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500248 ret = clk_prepare_enable(priv->mclk);
249 if (ret < 0) {
250 dev_err(card->dev,
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500251 "could not configure MCLK state\n");
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500252 return ret;
253 }
254 }
Hans de Goedebcd9a322018-05-08 17:35:53 +0200255 ret = byt_rt5640_prepare_and_enable_pll1(codec_dai, 48000);
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500256 } else {
257 /*
258 * Set codec clock source to internal clock before
259 * turning off the platform clock. Codec needs clock
260 * for Jack detection and button press
261 */
262 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK,
Pierre-Louis Bossart60448b02017-01-04 15:44:52 -0600263 48000 * 512,
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500264 SND_SOC_CLOCK_IN);
265 if (!ret) {
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500266 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500267 clk_disable_unprepare(priv->mclk);
268 }
269 }
270
271 if (ret < 0) {
272 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
273 return ret;
274 }
275
276 return 0;
277}
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -0600278
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600279static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530280 SND_SOC_DAPM_HP("Headphone", NULL),
281 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600282 SND_SOC_DAPM_MIC("Internal Mic", NULL),
283 SND_SOC_DAPM_SPK("Speaker", NULL),
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500284 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
285 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
286 SND_SOC_DAPM_POST_PMD),
287
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530288};
289
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600290static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500291 {"Headphone", NULL, "Platform Clock"},
292 {"Headset Mic", NULL, "Platform Clock"},
293 {"Internal Mic", NULL, "Platform Clock"},
294 {"Speaker", NULL, "Platform Clock"},
295
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530296 {"Headset Mic", NULL, "MICBIAS1"},
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600297 {"IN2P", NULL, "Headset Mic"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530298 {"Headphone", NULL, "HPOL"},
299 {"Headphone", NULL, "HPOR"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530300};
301
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600302static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
303 {"DMIC1", NULL, "Internal Mic"},
304};
305
306static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
307 {"DMIC2", NULL, "Internal Mic"},
308};
309
310static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
311 {"Internal Mic", NULL, "MICBIAS1"},
312 {"IN1P", NULL, "Internal Mic"},
313};
314
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -0500315static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
316 {"Internal Mic", NULL, "MICBIAS1"},
317 {"IN3P", NULL, "Internal Mic"},
318};
319
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500320static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
321 {"ssp2 Tx", NULL, "codec_out0"},
322 {"ssp2 Tx", NULL, "codec_out1"},
323 {"codec_in0", NULL, "ssp2 Rx"},
324 {"codec_in1", NULL, "ssp2 Rx"},
325
326 {"AIF1 Playback", NULL, "ssp2 Tx"},
327 {"ssp2 Rx", NULL, "AIF1 Capture"},
328};
329
330static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
331 {"ssp2 Tx", NULL, "codec_out0"},
332 {"ssp2 Tx", NULL, "codec_out1"},
333 {"codec_in0", NULL, "ssp2 Rx"},
334 {"codec_in1", NULL, "ssp2 Rx"},
335
336 {"AIF2 Playback", NULL, "ssp2 Tx"},
337 {"ssp2 Rx", NULL, "AIF2 Capture"},
338};
339
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500340static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
341 {"ssp0 Tx", NULL, "modem_out"},
342 {"modem_in", NULL, "ssp0 Rx"},
343
344 {"AIF1 Playback", NULL, "ssp0 Tx"},
345 {"ssp0 Rx", NULL, "AIF1 Capture"},
346};
347
348static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
349 {"ssp0 Tx", NULL, "modem_out"},
350 {"modem_in", NULL, "ssp0 Rx"},
351
352 {"AIF2 Playback", NULL, "ssp0 Tx"},
353 {"ssp0 Rx", NULL, "AIF2 Capture"},
354};
355
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500356static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
357 {"Speaker", NULL, "SPOLP"},
358 {"Speaker", NULL, "SPOLN"},
359 {"Speaker", NULL, "SPORP"},
360 {"Speaker", NULL, "SPORN"},
361};
362
363static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
364 {"Speaker", NULL, "SPOLP"},
365 {"Speaker", NULL, "SPOLN"},
366};
367
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600368static const struct snd_kcontrol_new byt_rt5640_controls[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530369 SOC_DAPM_PIN_SWITCH("Headphone"),
370 SOC_DAPM_PIN_SWITCH("Headset Mic"),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600371 SOC_DAPM_PIN_SWITCH("Internal Mic"),
372 SOC_DAPM_PIN_SWITCH("Speaker"),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530373};
374
Hans de Goede77323102018-05-13 09:24:28 +0200375static struct snd_soc_jack_pin rt5640_pins[] = {
376 {
377 .pin = "Headphone",
378 .mask = SND_JACK_HEADPHONE,
379 },
380 {
381 .pin = "Headset Mic",
382 .mask = SND_JACK_MICROPHONE,
383 },
384};
385
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600386static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530387 struct snd_pcm_hw_params *params)
388{
Kuninori Morimoto2207b932020-07-27 10:08:29 +0900389 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +0900390 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530391
Hans de Goedebcd9a322018-05-08 17:35:53 +0200392 return byt_rt5640_prepare_and_enable_pll1(dai, params_rate(params));
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530393}
394
Hans de Goede3c0d0112018-05-13 09:24:32 +0200395/* Please keep this list alphabetically sorted */
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600396static const struct dmi_system_id byt_rt5640_quirk_table[] = {
Hans de Goedeec8e8412018-05-13 09:24:34 +0200397 { /* Acer Iconia Tab 8 W1-810 */
398 .matches = {
399 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
400 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
401 },
402 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
403 BYT_RT5640_JD_SRC_JD1_IN4P |
Hans de Goedef12a0a32018-06-03 15:42:32 +0200404 BYT_RT5640_OVCD_TH_1500UA |
Hans de Goedeec8e8412018-05-13 09:24:34 +0200405 BYT_RT5640_OVCD_SF_0P75 |
406 BYT_RT5640_SSP0_AIF1 |
407 BYT_RT5640_MCLK_EN),
408 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600409 {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600410 .matches = {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200411 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
412 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
413 },
Hans de Goede0bb88772019-11-19 15:51:38 +0100414 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
415 BYT_RT5640_JD_SRC_JD2_IN4N |
416 BYT_RT5640_OVCD_TH_2000UA |
417 BYT_RT5640_OVCD_SF_0P75 |
418 BYT_RT5640_SSP0_AIF1 |
419 BYT_RT5640_MCLK_EN),
Hans de Goede3c0d0112018-05-13 09:24:32 +0200420 },
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 = {
Chris Chiu1bea2252020-12-08 14:04:14 +0800433 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
434 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 140 CESIUM"),
435 },
436 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
437 BYT_RT5640_JD_SRC_JD2_IN4N |
438 BYT_RT5640_OVCD_TH_2000UA |
439 BYT_RT5640_OVCD_SF_0P75 |
440 BYT_RT5640_SSP0_AIF1 |
441 BYT_RT5640_MCLK_EN),
442 },
443 {
444 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500445 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
Stephan Gerhold51a13e42019-01-02 20:39:08 +0100446 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
447 },
448 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
449 BYT_RT5640_JD_SRC_JD2_IN4N |
450 BYT_RT5640_OVCD_TH_2000UA |
451 BYT_RT5640_OVCD_SF_0P75 |
452 BYT_RT5640_SSP0_AIF1 |
453 BYT_RT5640_MCLK_EN),
454 },
455 {
456 .matches = {
457 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500458 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600459 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500460 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
Hans de Goede77323102018-05-13 09:24:28 +0200461 BYT_RT5640_JD_SRC_JD2_IN4N |
462 BYT_RT5640_OVCD_TH_2000UA |
463 BYT_RT5640_OVCD_SF_0P75 |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500464 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600465 },
466 {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600467 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500468 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
469 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
470 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500471 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
472 BYT_RT5640_MONO_SPEAKER |
473 BYT_RT5640_DIFF_MIC |
474 BYT_RT5640_SSP0_AIF2 |
475 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500476 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200477 { /* Chuwi Vi8 (CWI506) */
478 .matches = {
479 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"),
480 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "i86"),
481 /* The above are too generic, also match BIOS info */
482 DMI_MATCH(DMI_BIOS_VERSION, "CHUWI.D86JLBNR"),
483 },
484 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
485 BYT_RT5640_MONO_SPEAKER |
486 BYT_RT5640_SSP0_AIF1 |
487 BYT_RT5640_MCLK_EN),
488 },
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500489 {
Hans de Goeded5a18262018-06-08 10:19:25 +0200490 /* Chuwi Vi10 (CWI505) */
491 .matches = {
492 DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
493 DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"),
494 DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
495 DMI_MATCH(DMI_PRODUCT_NAME, "S165"),
496 },
497 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
498 BYT_RT5640_JD_SRC_JD2_IN4N |
499 BYT_RT5640_OVCD_TH_2000UA |
500 BYT_RT5640_OVCD_SF_0P75 |
501 BYT_RT5640_DIFF_MIC |
502 BYT_RT5640_SSP0_AIF1 |
503 BYT_RT5640_MCLK_EN),
504 },
505 {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500506 .matches = {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200507 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
508 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
509 },
510 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP),
511 },
Hans de Goede9ee6f8a2018-07-01 11:30:23 +0200512 { /* Connect Tablet 9 */
513 .matches = {
514 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Connect"),
515 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Tablet 9"),
516 },
517 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
518 BYT_RT5640_MONO_SPEAKER |
519 BYT_RT5640_SSP0_AIF1 |
520 BYT_RT5640_MCLK_EN),
521 },
Hans de Goede3c0d0112018-05-13 09:24:32 +0200522 {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200523 .matches = {
Hans de Goede6748fb72018-05-13 09:24:27 +0200524 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500525 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600526 },
Hans de Goede6748fb72018-05-13 09:24:27 +0200527 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
Hans de Goede77323102018-05-13 09:24:28 +0200528 BYT_RT5640_JD_SRC_JD2_IN4N |
529 BYT_RT5640_OVCD_TH_2000UA |
530 BYT_RT5640_OVCD_SF_0P75 |
Hans de Goede6748fb72018-05-13 09:24:27 +0200531 BYT_RT5640_MONO_SPEAKER |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500532 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600533 },
Hans de Goedebdea43f2021-02-16 22:35:52 +0100534 { /* Estar Beauty HD MID 7316R */
535 .matches = {
536 DMI_MATCH(DMI_SYS_VENDOR, "Estar"),
537 DMI_MATCH(DMI_PRODUCT_NAME, "eSTAR BEAUTY HD Intel Quad core"),
538 },
539 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
540 BYT_RT5640_MONO_SPEAKER |
541 BYT_RT5640_SSP0_AIF1 |
542 BYT_RT5640_MCLK_EN),
543 },
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600544 {
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600545 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500546 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
547 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600548 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500549 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
550 BYT_RT5640_MCLK_EN),
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600551 },
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100552 { /* HP Pavilion x2 10-k0XX, 10-n0XX */
Hans de Goedeec8e8412018-05-13 09:24:34 +0200553 .matches = {
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100554 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
555 DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion x2 Detachable"),
Hans de Goedeec8e8412018-05-13 09:24:34 +0200556 },
557 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
558 BYT_RT5640_JD_SRC_JD2_IN4N |
559 BYT_RT5640_OVCD_TH_1500UA |
560 BYT_RT5640_OVCD_SF_0P75 |
561 BYT_RT5640_SSP0_AIF1 |
562 BYT_RT5640_MCLK_EN),
563 },
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100564 { /* HP Pavilion x2 10-p0XX */
565 .matches = {
566 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
567 DMI_MATCH(DMI_PRODUCT_NAME, "HP x2 Detachable 10-p0XX"),
568 },
569 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
570 BYT_RT5640_JD_SRC_JD1_IN4P |
571 BYT_RT5640_OVCD_TH_1500UA |
572 BYT_RT5640_OVCD_SF_0P75 |
573 BYT_RT5640_MCLK_EN),
574 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200575 { /* HP Stream 7 */
576 .matches = {
577 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
578 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Stream 7 Tablet"),
579 },
580 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
581 BYT_RT5640_MONO_SPEAKER |
582 BYT_RT5640_JD_NOT_INV |
583 BYT_RT5640_SSP0_AIF1 |
584 BYT_RT5640_MCLK_EN),
585 },
586 { /* I.T.Works TW891 */
587 .matches = {
588 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
589 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
590 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
591 DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
592 },
593 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
594 BYT_RT5640_MONO_SPEAKER |
595 BYT_RT5640_SSP0_AIF1 |
596 BYT_RT5640_MCLK_EN),
597 },
598 { /* Lamina I8270 / T701BR.SE */
599 .matches = {
600 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Lamina"),
601 DMI_EXACT_MATCH(DMI_BOARD_NAME, "T701BR.SE"),
602 },
603 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
604 BYT_RT5640_MONO_SPEAKER |
605 BYT_RT5640_JD_NOT_INV |
606 BYT_RT5640_SSP0_AIF1 |
607 BYT_RT5640_MCLK_EN),
608 },
Hans de Goede81583af2018-07-07 12:22:10 +0200609 { /* Lenovo Miix 2 8 */
610 .matches = {
611 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
612 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "20326"),
613 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Hiking"),
614 },
615 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
616 BYT_RT5640_JD_SRC_JD2_IN4N |
617 BYT_RT5640_OVCD_TH_2000UA |
618 BYT_RT5640_OVCD_SF_0P75 |
619 BYT_RT5640_MONO_SPEAKER |
620 BYT_RT5640_MCLK_EN),
621 },
Hans de Goede260c48b2018-08-12 13:42:06 +0200622 { /* Linx Linx7 tablet */
623 .matches = {
624 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LINX"),
625 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LINX7"),
626 },
627 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
628 BYT_RT5640_MONO_SPEAKER |
629 BYT_RT5640_JD_NOT_INV |
630 BYT_RT5640_SSP0_AIF1 |
631 BYT_RT5640_MCLK_EN),
632 },
Hans de Goededf330322021-01-09 22:01:19 +0100633 { /* Mele PCG03 Mini PC */
634 .matches = {
635 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Mini PC"),
636 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Mini PC"),
637 },
638 .driver_data = (void *)(BYT_RT5640_NO_INTERNAL_MIC_MAP |
639 BYT_RT5640_NO_SPEAKERS |
640 BYT_RT5640_SSP0_AIF1),
641 },
Hans de Goede6a013712020-09-01 10:06:23 +0200642 { /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */
643 .matches = {
644 DMI_MATCH(DMI_SYS_VENDOR, "MPMAN"),
645 DMI_MATCH(DMI_PRODUCT_NAME, "Converter9"),
646 },
647 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
648 BYT_RT5640_MONO_SPEAKER |
649 BYT_RT5640_SSP0_AIF1 |
650 BYT_RT5640_MCLK_EN),
651 },
Hans de Goedec8b78f22020-04-05 15:37:26 +0200652 {
653 /* MPMAN MPWIN895CL */
654 .matches = {
655 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MPMAN"),
656 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MPWIN8900CL"),
657 },
658 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
659 BYT_RT5640_MONO_SPEAKER |
660 BYT_RT5640_SSP0_AIF1 |
661 BYT_RT5640_MCLK_EN),
662 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200663 { /* MSI S100 tablet */
664 .matches = {
665 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
666 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "S100"),
667 },
668 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
669 BYT_RT5640_JD_SRC_JD2_IN4N |
670 BYT_RT5640_OVCD_TH_2000UA |
671 BYT_RT5640_OVCD_SF_0P75 |
672 BYT_RT5640_MONO_SPEAKER |
673 BYT_RT5640_DIFF_MIC |
674 BYT_RT5640_MCLK_EN),
675 },
Hans de Goede6cea3592018-06-03 15:42:31 +0200676 { /* Nuvison/TMax TM800W560 */
677 .matches = {
678 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TMAX"),
679 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TM800W560L"),
680 },
681 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
682 BYT_RT5640_JD_SRC_JD2_IN4N |
683 BYT_RT5640_OVCD_TH_2000UA |
684 BYT_RT5640_OVCD_SF_0P75 |
685 BYT_RT5640_JD_NOT_INV |
686 BYT_RT5640_DIFF_MIC |
687 BYT_RT5640_SSP0_AIF1 |
688 BYT_RT5640_MCLK_EN),
689 },
Hans de Goede260c48b2018-08-12 13:42:06 +0200690 { /* Onda v975w */
691 .matches = {
692 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
693 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
694 /* The above are too generic, also match BIOS info */
695 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "5.6.5"),
696 DMI_EXACT_MATCH(DMI_BIOS_DATE, "07/25/2014"),
697 },
698 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
699 BYT_RT5640_JD_SRC_JD2_IN4N |
700 BYT_RT5640_OVCD_TH_2000UA |
701 BYT_RT5640_OVCD_SF_0P75 |
702 BYT_RT5640_DIFF_MIC |
703 BYT_RT5640_MCLK_EN),
704 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200705 { /* Pipo W4 */
706 .matches = {
707 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
708 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
709 /* The above are too generic, also match BIOS info */
710 DMI_MATCH(DMI_BIOS_VERSION, "V8L_WIN32_CHIPHD"),
711 },
712 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
713 BYT_RT5640_MONO_SPEAKER |
714 BYT_RT5640_SSP0_AIF1 |
715 BYT_RT5640_MCLK_EN),
716 },
717 { /* Point of View Mobii TAB-P800W (V2.0) */
718 .matches = {
719 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
720 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
721 /* The above are too generic, also match BIOS info */
722 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1014"),
723 DMI_EXACT_MATCH(DMI_BIOS_DATE, "10/24/2014"),
724 },
725 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
726 BYT_RT5640_JD_SRC_JD2_IN4N |
727 BYT_RT5640_OVCD_TH_2000UA |
728 BYT_RT5640_OVCD_SF_0P75 |
729 BYT_RT5640_MONO_SPEAKER |
730 BYT_RT5640_DIFF_MIC |
731 BYT_RT5640_SSP0_AIF2 |
732 BYT_RT5640_MCLK_EN),
733 },
734 { /* Point of View Mobii TAB-P800W (V2.1) */
735 .matches = {
736 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
737 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
738 /* The above are too generic, also match BIOS info */
739 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1013"),
740 DMI_EXACT_MATCH(DMI_BIOS_DATE, "08/22/2014"),
741 },
742 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
743 BYT_RT5640_JD_SRC_JD2_IN4N |
744 BYT_RT5640_OVCD_TH_2000UA |
745 BYT_RT5640_OVCD_SF_0P75 |
746 BYT_RT5640_MONO_SPEAKER |
747 BYT_RT5640_DIFF_MIC |
748 BYT_RT5640_SSP0_AIF2 |
749 BYT_RT5640_MCLK_EN),
750 },
Hans de Goede02e5af62018-12-08 14:01:14 +0100751 { /* Point of View Mobii TAB-P1005W-232 (V2.0) */
752 .matches = {
753 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "POV"),
754 DMI_EXACT_MATCH(DMI_BOARD_NAME, "I102A"),
755 },
756 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
757 BYT_RT5640_JD_SRC_JD2_IN4N |
758 BYT_RT5640_OVCD_TH_2000UA |
759 BYT_RT5640_OVCD_SF_0P75 |
760 BYT_RT5640_DIFF_MIC |
761 BYT_RT5640_SSP0_AIF1 |
762 BYT_RT5640_MCLK_EN),
763 },
Irina Tirdea0565e772016-08-12 16:27:58 -0500764 {
Hans de Goede271248f2018-12-08 14:01:13 +0100765 /* Prowise PT301 */
766 .matches = {
767 DMI_MATCH(DMI_SYS_VENDOR, "Prowise"),
768 DMI_MATCH(DMI_PRODUCT_NAME, "PT301"),
769 },
770 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
771 BYT_RT5640_JD_SRC_JD2_IN4N |
772 BYT_RT5640_OVCD_TH_2000UA |
773 BYT_RT5640_OVCD_SF_0P75 |
774 BYT_RT5640_DIFF_MIC |
775 BYT_RT5640_SSP0_AIF1 |
776 BYT_RT5640_MCLK_EN),
777 },
778 {
Hans de Goede7eccc052019-12-03 23:14:42 +0100779 /* Teclast X89 */
Irina Tirdea0565e772016-08-12 16:27:58 -0500780 .matches = {
Pierre-Louis Bossartec1c90e2016-08-12 16:27:59 -0500781 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
782 DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
783 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500784 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
Hans de Goede7eccc052019-12-03 23:14:42 +0100785 BYT_RT5640_JD_SRC_JD1_IN4P |
786 BYT_RT5640_OVCD_TH_2000UA |
787 BYT_RT5640_OVCD_SF_1P0 |
788 BYT_RT5640_SSP0_AIF1 |
789 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossartec1c90e2016-08-12 16:27:59 -0500790 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200791 { /* Toshiba Satellite Click Mini L9W-B */
792 .matches = {
793 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
794 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
795 },
796 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
797 BYT_RT5640_JD_SRC_JD2_IN4N |
798 BYT_RT5640_OVCD_TH_1500UA |
799 BYT_RT5640_OVCD_SF_0P75 |
800 BYT_RT5640_SSP0_AIF1 |
801 BYT_RT5640_MCLK_EN),
802 },
Hans de Goede0e0e10f2020-05-18 09:24:16 +0200803 { /* Toshiba Encore WT8-A */
804 .matches = {
805 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
806 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"),
807 },
808 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
809 BYT_RT5640_JD_SRC_JD2_IN4N |
810 BYT_RT5640_OVCD_TH_2000UA |
811 BYT_RT5640_OVCD_SF_0P75 |
812 BYT_RT5640_JD_NOT_INV |
813 BYT_RT5640_MCLK_EN),
814 },
Hans de Goede199a5e82020-06-08 22:46:33 +0200815 { /* Toshiba Encore WT10-A */
816 .matches = {
817 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
818 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"),
819 },
820 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
821 BYT_RT5640_JD_SRC_JD1_IN4P |
822 BYT_RT5640_OVCD_TH_2000UA |
823 BYT_RT5640_OVCD_SF_0P75 |
824 BYT_RT5640_SSP0_AIF2 |
825 BYT_RT5640_MCLK_EN),
826 },
Hans de Goedee1317cc2021-02-16 22:35:53 +0100827 { /* Voyo Winpad A15 */
828 .matches = {
829 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
830 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
831 /* Above strings are too generic, also match on BIOS date */
832 DMI_MATCH(DMI_BIOS_DATE, "11/20/2014"),
833 },
834 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
835 BYT_RT5640_JD_SRC_JD2_IN4N |
836 BYT_RT5640_OVCD_TH_2000UA |
837 BYT_RT5640_OVCD_SF_0P75 |
838 BYT_RT5640_DIFF_MIC |
839 BYT_RT5640_MCLK_EN),
840 },
Hans de Goede3c0d0112018-05-13 09:24:32 +0200841 { /* Catch-all for generic Insyde tablets, must be last */
youling25757180042017-01-04 15:44:53 -0600842 .matches = {
843 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
844 },
Hans de Goede96a388fe2018-05-13 09:24:30 +0200845 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500846 BYT_RT5640_MCLK_EN |
847 BYT_RT5640_SSP0_AIF1),
youling25757180042017-01-04 15:44:53 -0600848
849 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600850 {}
851};
852
Hans de Goede6a7c05e2018-05-08 17:35:54 +0200853/*
854 * Note this MUST be called before snd_soc_register_card(), so that the props
855 * are in place before the codec component driver's probe function parses them.
856 */
857static int byt_rt5640_add_codec_device_props(const char *i2c_dev_name)
858{
859 struct property_entry props[MAX_NO_PROPS] = {};
860 struct device *i2c_dev;
861 int ret, cnt = 0;
862
863 i2c_dev = bus_find_device_by_name(&i2c_bus_type, NULL, i2c_dev_name);
864 if (!i2c_dev)
865 return -EPROBE_DEFER;
866
867 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
Hans de Goedea3ad2912018-05-13 09:24:26 +0200868 case BYT_RT5640_DMIC1_MAP:
869 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin",
870 RT5640_DMIC1_DATA_PIN_IN1P);
871 break;
872 case BYT_RT5640_DMIC2_MAP:
873 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin",
874 RT5640_DMIC2_DATA_PIN_IN1N);
875 break;
Hans de Goede6a7c05e2018-05-08 17:35:54 +0200876 case BYT_RT5640_IN1_MAP:
877 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
878 props[cnt++] =
879 PROPERTY_ENTRY_BOOL("realtek,in1-differential");
880 break;
881 case BYT_RT5640_IN3_MAP:
882 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
883 props[cnt++] =
884 PROPERTY_ENTRY_BOOL("realtek,in3-differential");
885 break;
886 }
887
Hans de Goede77323102018-05-13 09:24:28 +0200888 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
889 props[cnt++] = PROPERTY_ENTRY_U32(
890 "realtek,jack-detect-source",
891 BYT_RT5640_JDSRC(byt_rt5640_quirk));
892
893 props[cnt++] = PROPERTY_ENTRY_U32(
894 "realtek,over-current-threshold-microamp",
895 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
896
897 props[cnt++] = PROPERTY_ENTRY_U32(
898 "realtek,over-current-scale-factor",
899 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
900 }
901
902 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
903 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted");
904
Hans de Goede6a7c05e2018-05-08 17:35:54 +0200905 ret = device_add_properties(i2c_dev, props);
906 put_device(i2c_dev);
907
908 return ret;
909}
910
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600911static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
912{
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600913 struct snd_soc_card *card = runtime->card;
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500914 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +0900915 struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
Hans de Goede46466ab2021-01-09 22:01:18 +0100916 const struct snd_soc_dapm_route *custom_map = NULL;
917 int num_routes = 0;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500918 int ret;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600919
920 card->dapm.idle_bias_off = true;
921
Hans de Goede77323102018-05-13 09:24:28 +0200922 /* Start with RC clk for jack-detect (we disable MCLK below) */
923 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
924 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
925 RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_RCCLK);
926
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000927 rt5640_sel_asrc_clk_src(component,
Pierre-Louis Bossart0ec66e2d2016-01-04 17:20:27 -0600928 RT5640_DA_STEREO_FILTER |
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500929 RT5640_DA_MONO_L_FILTER |
930 RT5640_DA_MONO_R_FILTER |
931 RT5640_AD_STEREO_FILTER |
932 RT5640_AD_MONO_L_FILTER |
933 RT5640_AD_MONO_R_FILTER,
Pierre-Louis Bossart0ec66e2d2016-01-04 17:20:27 -0600934 RT5640_CLK_SEL_ASRC);
935
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600936 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
937 ARRAY_SIZE(byt_rt5640_controls));
938 if (ret) {
939 dev_err(card->dev, "unable to add card controls\n");
940 return ret;
941 }
942
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600943 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
944 case BYT_RT5640_IN1_MAP:
945 custom_map = byt_rt5640_intmic_in1_map;
946 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
947 break;
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -0500948 case BYT_RT5640_IN3_MAP:
949 custom_map = byt_rt5640_intmic_in3_map;
950 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
951 break;
Hans de Goede46466ab2021-01-09 22:01:18 +0100952 case BYT_RT5640_DMIC1_MAP:
953 custom_map = byt_rt5640_intmic_dmic1_map;
954 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
955 break;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600956 case BYT_RT5640_DMIC2_MAP:
957 custom_map = byt_rt5640_intmic_dmic2_map;
958 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
959 break;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600960 }
961
962 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
963 if (ret)
964 return ret;
965
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500966 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
967 ret = snd_soc_dapm_add_routes(&card->dapm,
968 byt_rt5640_ssp2_aif2_map,
969 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500970 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
971 ret = snd_soc_dapm_add_routes(&card->dapm,
972 byt_rt5640_ssp0_aif1_map,
973 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
974 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
975 ret = snd_soc_dapm_add_routes(&card->dapm,
976 byt_rt5640_ssp0_aif2_map,
977 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500978 } else {
979 ret = snd_soc_dapm_add_routes(&card->dapm,
980 byt_rt5640_ssp2_aif1_map,
981 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
982 }
983 if (ret)
984 return ret;
985
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500986 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
987 ret = snd_soc_dapm_add_routes(&card->dapm,
988 byt_rt5640_mono_spk_map,
989 ARRAY_SIZE(byt_rt5640_mono_spk_map));
Hans de Goede1851ccf2021-01-09 22:01:17 +0100990 } else if (!(byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)) {
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500991 ret = snd_soc_dapm_add_routes(&card->dapm,
992 byt_rt5640_stereo_spk_map,
993 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
994 }
995 if (ret)
996 return ret;
997
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500998 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500999 /*
1000 * The firmware might enable the clock at
1001 * boot (this information may or may not
1002 * be reflected in the enable clock register).
1003 * To change the rate we must disable the clock
1004 * first to cover these cases. Due to common
1005 * clock framework restrictions that do not allow
1006 * to disable a clock that has not been enabled,
1007 * we need to enable the clock first.
1008 */
1009 ret = clk_prepare_enable(priv->mclk);
1010 if (!ret)
1011 clk_disable_unprepare(priv->mclk);
1012
1013 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
1014 ret = clk_set_rate(priv->mclk, 25000000);
1015 else
1016 ret = clk_set_rate(priv->mclk, 19200000);
1017
Hans de Goede77323102018-05-13 09:24:28 +02001018 if (ret) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001019 dev_err(card->dev, "unable to set MCLK rate\n");
Hans de Goede77323102018-05-13 09:24:28 +02001020 return ret;
1021 }
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001022 }
1023
Hans de Goede77323102018-05-13 09:24:28 +02001024 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
1025 ret = snd_soc_card_jack_new(card, "Headset",
1026 SND_JACK_HEADSET | SND_JACK_BTN_0,
1027 &priv->jack, rt5640_pins,
1028 ARRAY_SIZE(rt5640_pins));
1029 if (ret) {
1030 dev_err(card->dev, "Jack creation failed %d\n", ret);
1031 return ret;
1032 }
1033 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
1034 KEY_PLAYPAUSE);
1035 snd_soc_component_set_jack(component, &priv->jack, NULL);
1036 }
1037
1038 return 0;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001039}
1040
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001041static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301042 struct snd_pcm_hw_params *params)
1043{
1044 struct snd_interval *rate = hw_param_interval(params,
1045 SNDRV_PCM_HW_PARAM_RATE);
1046 struct snd_interval *channels = hw_param_interval(params,
1047 SNDRV_PCM_HW_PARAM_CHANNELS);
Erik Bussing332719b2020-01-15 17:46:16 +01001048 int ret, bits;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301049
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001050 /* The DSP will covert the FE rate to 48k, stereo */
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301051 rate->min = rate->max = 48000;
1052 channels->min = channels->max = 2;
1053
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001054 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
Erik Bussing332719b2020-01-15 17:46:16 +01001055 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
Pierre-Louis Bossart8f98307d2016-08-16 18:28:22 -05001056 /* set SSP0 to 16-bit */
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001057 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
Erik Bussing332719b2020-01-15 17:46:16 +01001058 bits = 16;
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001059 } else {
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001060 /* set SSP2 to 24-bit */
1061 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
Erik Bussing332719b2020-01-15 17:46:16 +01001062 bits = 24;
Sebastien Guiriec3f27ded2015-12-17 20:35:39 -06001063 }
Erik Bussing332719b2020-01-15 17:46:16 +01001064
1065 /*
1066 * Default mode for SSP configuration is TDM 4 slot, override config
1067 * with explicit setting to I2S 2ch. The word length is set with
1068 * dai_set_tdm_slot() since there is no other API exposed
1069 */
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +09001070 ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
Erik Bussing332719b2020-01-15 17:46:16 +01001071 SND_SOC_DAIFMT_I2S |
1072 SND_SOC_DAIFMT_NB_NF |
1073 SND_SOC_DAIFMT_CBS_CFS);
1074 if (ret < 0) {
1075 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
1076 return ret;
1077 }
1078
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +09001079 ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);
Erik Bussing332719b2020-01-15 17:46:16 +01001080 if (ret < 0) {
1081 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
1082 return ret;
1083 }
1084
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301085 return 0;
1086}
1087
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001088static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301089{
Lars-Peter Clausend0a1b662015-10-18 15:39:30 +02001090 return snd_pcm_hw_constraint_single(substream->runtime,
1091 SNDRV_PCM_HW_PARAM_RATE, 48000);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301092}
1093
Julia Lawall9b6fdef2016-10-15 16:55:49 +02001094static const struct snd_soc_ops byt_rt5640_aif1_ops = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001095 .startup = byt_rt5640_aif1_startup,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301096};
1097
Julia Lawall9b6fdef2016-10-15 16:55:49 +02001098static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001099 .hw_params = byt_rt5640_aif1_hw_params,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301100};
1101
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001102SND_SOC_DAILINK_DEF(dummy,
1103 DAILINK_COMP_ARRAY(COMP_DUMMY()));
1104
1105SND_SOC_DAILINK_DEF(media,
1106 DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
1107
1108SND_SOC_DAILINK_DEF(deepbuffer,
1109 DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
1110
1111SND_SOC_DAILINK_DEF(ssp2_port,
1112 /* overwritten for ssp0 routing */
1113 DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
1114SND_SOC_DAILINK_DEF(ssp2_codec,
1115 DAILINK_COMP_ARRAY(COMP_CODEC(
1116 /* overwritten with HID */ "i2c-10EC5640:00",
1117 /* changed w/ quirk */ "rt5640-aif1")));
1118
1119SND_SOC_DAILINK_DEF(platform,
1120 DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
1121
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001122static struct snd_soc_dai_link byt_rt5640_dais[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301123 [MERR_DPCM_AUDIO] = {
1124 .name = "Baytrail Audio Port",
1125 .stream_name = "Baytrail Audio",
Takashi Iwai6e4cac22017-04-24 14:09:55 +02001126 .nonatomic = true,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301127 .dynamic = 1,
1128 .dpcm_playback = 1,
1129 .dpcm_capture = 1,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001130 .ops = &byt_rt5640_aif1_ops,
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001131 SND_SOC_DAILINK_REG(media, dummy, platform),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301132 },
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001133 [MERR_DPCM_DEEP_BUFFER] = {
1134 .name = "Deep-Buffer Audio Port",
1135 .stream_name = "Deep-Buffer Audio",
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001136 .nonatomic = true,
1137 .dynamic = 1,
1138 .dpcm_playback = 1,
1139 .ops = &byt_rt5640_aif1_ops,
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001140 SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001141 },
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301142 /* back ends */
1143 {
1144 .name = "SSP2-Codec",
Pierre-Louis Bossart149f7752017-10-12 18:38:04 -05001145 .id = 0,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301146 .no_pcm = 1,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301147 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
1148 | SND_SOC_DAIFMT_CBS_CFS,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001149 .be_hw_params_fixup = byt_rt5640_codec_fixup,
Takashi Iwai6e4cac22017-04-24 14:09:55 +02001150 .nonatomic = true,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301151 .dpcm_playback = 1,
1152 .dpcm_capture = 1,
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001153 .init = byt_rt5640_init,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001154 .ops = &byt_rt5640_be_ssp2_ops,
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001155 SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301156 },
1157};
1158
1159/* SoC card */
Hans de Goede77323102018-05-13 09:24:28 +02001160static char byt_rt5640_codec_name[SND_ACPI_I2C_ID_LEN];
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001161#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
Hans de Goede063422c2018-05-13 09:24:35 +02001162static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001163#endif
Jaroslav Kysela0d5c8182019-12-04 15:15:45 -06001164static char byt_rt5640_components[32]; /* = "cfg-spk:* cfg-mic:*" */
Hans de Goede77323102018-05-13 09:24:28 +02001165
1166static int byt_rt5640_suspend(struct snd_soc_card *card)
1167{
1168 struct snd_soc_component *component;
1169
1170 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1171 return 0;
1172
Kuninori Morimotof70f18f72018-09-18 01:29:55 +00001173 for_each_card_components(card, component) {
Hans de Goede77323102018-05-13 09:24:28 +02001174 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1175 dev_dbg(component->dev, "disabling jack detect before suspend\n");
1176 snd_soc_component_set_jack(component, NULL, NULL);
1177 break;
1178 }
1179 }
1180
1181 return 0;
1182}
1183
1184static int byt_rt5640_resume(struct snd_soc_card *card)
1185{
1186 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1187 struct snd_soc_component *component;
1188
1189 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1190 return 0;
1191
Kuninori Morimotof70f18f72018-09-18 01:29:55 +00001192 for_each_card_components(card, component) {
Hans de Goede77323102018-05-13 09:24:28 +02001193 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1194 dev_dbg(component->dev, "re-enabling jack detect after resume\n");
1195 snd_soc_component_set_jack(component, &priv->jack, NULL);
1196 break;
1197 }
1198 }
1199
1200 return 0;
1201}
1202
Pierre-Louis Bossartb4ecd582020-06-17 11:56:14 -05001203/* use space before codec name to simplify card ID, and simplify driver name */
Pierre-Louis Bossart41656c32020-11-12 16:38:16 -06001204#define SOF_CARD_NAME "bytcht rt5640" /* card name will be 'sof-bytcht rt5640' */
1205#define SOF_DRIVER_NAME "SOF"
1206
Pierre-Louis Bossartb4ecd582020-06-17 11:56:14 -05001207#define CARD_NAME "bytcr-rt5640"
1208#define DRIVER_NAME NULL /* card name will be used for driver name */
Pierre-Louis Bossartb4ecd582020-06-17 11:56:14 -05001209
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001210static struct snd_soc_card byt_rt5640_card = {
Axel Lin54d86972015-08-21 20:59:21 +08001211 .owner = THIS_MODULE,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001212 .dai_link = byt_rt5640_dais,
1213 .num_links = ARRAY_SIZE(byt_rt5640_dais),
1214 .dapm_widgets = byt_rt5640_widgets,
1215 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
1216 .dapm_routes = byt_rt5640_audio_map,
1217 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001218 .fully_routed = true,
Hans de Goede77323102018-05-13 09:24:28 +02001219 .suspend_pre = byt_rt5640_suspend,
1220 .resume_post = byt_rt5640_resume,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301221};
1222
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001223struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
1224 u64 aif_value; /* 1: AIF1, 2: AIF2 */
1225 u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
1226};
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001227
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001228static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301229{
Pierre-Louis Bossart05ff3122020-11-12 16:38:17 -06001230 struct device *dev = &pdev->dev;
Hans de Goede46466ab2021-01-09 22:01:18 +01001231 static const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3", "none" };
Hans de Goede1851ccf2021-01-09 22:01:17 +01001232 __maybe_unused const char *spk_type;
Hans de Goede6d1bfcc2018-05-13 09:24:33 +02001233 const struct dmi_system_id *dmi_id;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001234 struct byt_rt5640_private *priv;
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001235 struct snd_soc_acpi_mach *mach;
Pierre-Louis Bossartbd7661b2019-01-25 14:34:59 -06001236 const char *platform_name;
Andy Shevchenkoa320d892019-03-28 19:17:25 +02001237 struct acpi_device *adev;
Pierre-Louis Bossart41656c32020-11-12 16:38:16 -06001238 bool sof_parent;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001239 int ret_val = 0;
Pierre-Louis Bossart2193eb92017-10-12 18:38:05 -05001240 int dai_index = 0;
Hans de Goede1851ccf2021-01-09 22:01:17 +01001241 int i, cfg_spk;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001242
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -05001243 is_bytcr = false;
Jia-Ju Bai7a3a6322018-04-09 18:47:37 +08001244 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001245 if (!priv)
1246 return -ENOMEM;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301247
1248 /* register the soc card */
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001249 byt_rt5640_card.dev = &pdev->dev;
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001250 mach = byt_rt5640_card.dev->platform_data;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001251 snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001252
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001253 /* fix index of codec dai */
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001254 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001255 if (!strcmp(byt_rt5640_dais[i].codecs->name,
1256 "i2c-10EC5640:00")) {
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001257 dai_index = i;
1258 break;
1259 }
1260 }
1261
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001262 /* fixup codec name based on HID */
Andy Shevchenkoa320d892019-03-28 19:17:25 +02001263 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
1264 if (adev) {
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001265 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
Andy Shevchenkoa320d892019-03-28 19:17:25 +02001266 "i2c-%s", acpi_dev_name(adev));
1267 put_device(&adev->dev);
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001268 byt_rt5640_dais[dai_index].codecs->name = byt_rt5640_codec_name;
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001269 }
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301270
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001271 /*
1272 * swap SSP0 if bytcr is detected
1273 * (will be overridden if DMI quirk is detected)
1274 */
Pierre-Louis Bossart536cfd22019-05-30 06:50:11 -05001275 if (soc_intel_is_byt()) {
Pierre-Louis Bossart3ee1cd42018-11-01 16:34:50 -05001276 if (mach->mach_params.acpi_ipc_irq_index == 0)
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001277 is_bytcr = true;
1278 }
1279
1280 if (is_bytcr) {
1281 /*
1282 * Baytrail CR platforms may have CHAN package in BIOS, try
1283 * to find relevant routing quirk based as done on Windows
1284 * platforms. We have to read the information directly from the
1285 * BIOS, at this stage the card is not created and the links
1286 * with the codec driver/pdata are non-existent
1287 */
1288
1289 struct acpi_chan_package chan_package;
1290
1291 /* format specified: 2 64-bit integers */
1292 struct acpi_buffer format = {sizeof("NN"), "NN"};
1293 struct acpi_buffer state = {0, NULL};
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001294 struct snd_soc_acpi_package_context pkg_ctx;
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001295 bool pkg_found = false;
1296
1297 state.length = sizeof(chan_package);
1298 state.pointer = &chan_package;
1299
1300 pkg_ctx.name = "CHAN";
1301 pkg_ctx.length = 2;
1302 pkg_ctx.format = &format;
1303 pkg_ctx.state = &state;
1304 pkg_ctx.data_valid = false;
1305
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001306 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
1307 &pkg_ctx);
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001308 if (pkg_found) {
1309 if (chan_package.aif_value == 1) {
1310 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
1311 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
1312 } else if (chan_package.aif_value == 2) {
1313 dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n");
1314 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1315 } else {
1316 dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n");
1317 pkg_found = false;
1318 }
1319 }
1320
1321 if (!pkg_found) {
1322 /* no BIOS indications, assume SSP0-AIF2 connection */
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001323 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1324 }
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -06001325
1326 /* change defaults for Baytrail-CR capture */
Hans de Goede96a388fe2018-05-13 09:24:30 +02001327 byt_rt5640_quirk |= BYTCR_INPUT_DEFAULTS;
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -06001328 } else {
Hans de Goede56ff4402018-05-13 09:24:31 +02001329 byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP |
1330 BYT_RT5640_JD_SRC_JD2_IN4N |
1331 BYT_RT5640_OVCD_TH_2000UA |
1332 BYT_RT5640_OVCD_SF_0P75;
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001333 }
1334
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -06001335 /* check quirks before creating card */
Hans de Goede6d1bfcc2018-05-13 09:24:33 +02001336 dmi_id = dmi_first_match(byt_rt5640_quirk_table);
1337 if (dmi_id)
1338 byt_rt5640_quirk = (unsigned long)dmi_id->driver_data;
Pierre-Louis Bossart2fb2a192019-04-19 15:12:17 -05001339 if (quirk_override != -1) {
Pierre-Louis Bossart2697f3a2020-06-25 14:12:57 -05001340 dev_info(&pdev->dev, "Overriding quirk 0x%lx => 0x%x\n",
1341 byt_rt5640_quirk, quirk_override);
Takashi Iwai9f2cf732017-04-23 09:22:56 +02001342 byt_rt5640_quirk = quirk_override;
1343 }
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001344
1345 /* Must be called before register_card, also see declaration comment. */
1346 ret_val = byt_rt5640_add_codec_device_props(byt_rt5640_codec_name);
1347 if (ret_val)
1348 return ret_val;
1349
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -05001350 log_quirks(&pdev->dev);
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -06001351
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001352 if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
Nariman Etemadi29686832020-01-15 17:46:17 +01001353 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2))
1354 byt_rt5640_dais[dai_index].codecs->dai_name = "rt5640-aif2";
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -05001355
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001356 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
Nariman Etemadi29686832020-01-15 17:46:17 +01001357 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2))
1358 byt_rt5640_dais[dai_index].cpus->dai_name = "ssp0-port";
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001359
Pierre-Louis Bossart7735bce2017-09-08 12:43:52 -05001360 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001361 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
1362 if (IS_ERR(priv->mclk)) {
Pierre-Louis Bossart4a8b3a62016-12-16 10:55:49 -06001363 ret_val = PTR_ERR(priv->mclk);
1364
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001365 dev_err(&pdev->dev,
Pierre-Louis Bossart4a8b3a62016-12-16 10:55:49 -06001366 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
1367 ret_val);
1368
1369 /*
1370 * Fall back to bit clock usage for -ENOENT (clock not
1371 * available likely due to missing dependencies), bail
1372 * for all other errors, including -EPROBE_DEFER
1373 */
1374 if (ret_val != -ENOENT)
1375 return ret_val;
1376 byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001377 }
1378 }
1379
Hans de Goede1851ccf2021-01-09 22:01:17 +01001380 if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS) {
1381 cfg_spk = 0;
1382 spk_type = "none";
1383 } else if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1384 cfg_spk = 1;
1385 spk_type = "mono";
1386 } else {
1387 cfg_spk = 2;
1388 spk_type = "stereo";
1389 }
1390
Jaroslav Kysela0d5c8182019-12-04 15:15:45 -06001391 snprintf(byt_rt5640_components, sizeof(byt_rt5640_components),
Hans de Goede1851ccf2021-01-09 22:01:17 +01001392 "cfg-spk:%d cfg-mic:%s", cfg_spk,
Jaroslav Kysela0d5c8182019-12-04 15:15:45 -06001393 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1394 byt_rt5640_card.components = byt_rt5640_components;
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001395#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
Hans de Goede063422c2018-05-13 09:24:35 +02001396 snprintf(byt_rt5640_long_name, sizeof(byt_rt5640_long_name),
Hans de Goede1851ccf2021-01-09 22:01:17 +01001397 "bytcr-rt5640-%s-spk-%s-mic", spk_type,
Hans de Goede063422c2018-05-13 09:24:35 +02001398 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1399 byt_rt5640_card.long_name = byt_rt5640_long_name;
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001400#endif
Hans de Goede063422c2018-05-13 09:24:35 +02001401
Pierre-Louis Bossartbd7661b2019-01-25 14:34:59 -06001402 /* override plaform name, if required */
1403 platform_name = mach->mach_params.platform;
1404
1405 ret_val = snd_soc_fixup_dai_links_platform_name(&byt_rt5640_card,
1406 platform_name);
1407 if (ret_val)
1408 return ret_val;
1409
Pierre-Louis Bossart41656c32020-11-12 16:38:16 -06001410 sof_parent = snd_soc_acpi_sof_parent(&pdev->dev);
1411
1412 /* set card and driver name */
1413 if (sof_parent) {
1414 byt_rt5640_card.name = SOF_CARD_NAME;
1415 byt_rt5640_card.driver_name = SOF_DRIVER_NAME;
1416 } else {
1417 byt_rt5640_card.name = CARD_NAME;
1418 byt_rt5640_card.driver_name = DRIVER_NAME;
1419 }
1420
Pierre-Louis Bossart05ff3122020-11-12 16:38:17 -06001421 /* set pm ops */
1422 if (sof_parent)
1423 dev->driver->pm = &snd_soc_pm_ops;
1424
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001425 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
1426
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301427 if (ret_val) {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001428 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
1429 ret_val);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301430 return ret_val;
1431 }
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001432 platform_set_drvdata(pdev, &byt_rt5640_card);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301433 return ret_val;
1434}
1435
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001436static struct platform_driver snd_byt_rt5640_mc_driver = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301437 .driver = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001438 .name = "bytcr_rt5640",
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301439 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001440 .probe = snd_byt_rt5640_mc_probe,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301441};
1442
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001443module_platform_driver(snd_byt_rt5640_mc_driver);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301444
1445MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
1446MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
1447MODULE_LICENSE("GPL v2");
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001448MODULE_ALIAS("platform:bytcr_rt5640");