blob: b25ca99d9855431598281a4b3c9e2dae564ac424 [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 Goededd3e2022021-08-02 16:24:57 +020076#define BYT_RT5640_LINEOUT BIT(25)
Hans de Goede044c7652021-08-02 16:24:59 +020077#define BYT_RT5640_LINEOUT_AS_HP2 BIT(26)
Hans de Goede79c1123b2021-08-02 16:25:00 +020078#define BYT_RT5640_HSMIC2_ON_IN1 BIT(27)
Hans de Goede77323102018-05-13 09:24:28 +020079
Hans de Goede96a388fe2018-05-13 09:24:30 +020080#define BYTCR_INPUT_DEFAULTS \
81 (BYT_RT5640_IN3_MAP | \
Hans de Goede56ff4402018-05-13 09:24:31 +020082 BYT_RT5640_JD_SRC_JD1_IN4P | \
83 BYT_RT5640_OVCD_TH_2000UA | \
84 BYT_RT5640_OVCD_SF_0P75 | \
Hans de Goede96a388fe2018-05-13 09:24:30 +020085 BYT_RT5640_DIFF_MIC)
86
Hans de Goede77323102018-05-13 09:24:28 +020087/* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
88#define MAX_NO_PROPS 6
Hans de Goede6a7c05e2018-05-08 17:35:54 +020089
Irina Tirdeadf1a2772016-08-12 16:27:57 -050090struct byt_rt5640_private {
Hans de Goede77323102018-05-13 09:24:28 +020091 struct snd_soc_jack jack;
Irina Tirdeadf1a2772016-08-12 16:27:57 -050092 struct clk *mclk;
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -050093 struct device *codec_dev;
Irina Tirdeadf1a2772016-08-12 16:27:57 -050094};
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -050095static bool is_bytcr;
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060096
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -060097static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN;
Pierre-Louis Bossart2fb2a192019-04-19 15:12:17 -050098static int quirk_override = -1;
99module_param_named(quirk, quirk_override, int, 0444);
Takashi Iwai9f2cf732017-04-23 09:22:56 +0200100MODULE_PARM_DESC(quirk, "Board-specific quirk override");
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500101
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500102static void log_quirks(struct device *dev)
103{
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500104 int map;
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500105 bool has_mclk = false;
106 bool has_ssp0 = false;
107 bool has_ssp0_aif1 = false;
108 bool has_ssp0_aif2 = false;
109 bool has_ssp2_aif2 = false;
110
111 map = BYT_RT5640_MAP(byt_rt5640_quirk);
112 switch (map) {
113 case BYT_RT5640_DMIC1_MAP:
114 dev_info(dev, "quirk DMIC1_MAP enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500115 break;
116 case BYT_RT5640_DMIC2_MAP:
117 dev_info(dev, "quirk DMIC2_MAP enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500118 break;
119 case BYT_RT5640_IN1_MAP:
120 dev_info(dev, "quirk IN1_MAP enabled\n");
121 break;
122 case BYT_RT5640_IN3_MAP:
123 dev_info(dev, "quirk IN3_MAP enabled\n");
124 break;
Hans de Goede46466ab2021-01-09 22:01:18 +0100125 case BYT_RT5640_NO_INTERNAL_MIC_MAP:
126 dev_info(dev, "quirk NO_INTERNAL_MIC_MAP enabled\n");
127 break;
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500128 default:
129 dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
130 break;
131 }
Hans de Goede79c1123b2021-08-02 16:25:00 +0200132 if (byt_rt5640_quirk & BYT_RT5640_HSMIC2_ON_IN1)
133 dev_info(dev, "quirk HSMIC2_ON_IN1 enabled\n");
Hans de Goede77323102018-05-13 09:24:28 +0200134 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
135 dev_info(dev, "quirk realtek,jack-detect-source %ld\n",
136 BYT_RT5640_JDSRC(byt_rt5640_quirk));
137 dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n",
138 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
139 dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n",
140 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
141 }
142 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
143 dev_info(dev, "quirk JD_NOT_INV enabled\n");
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500144 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500145 dev_info(dev, "quirk MONO_SPEAKER enabled\n");
Hans de Goede1851ccf2021-01-09 22:01:17 +0100146 if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)
147 dev_info(dev, "quirk NO_SPEAKERS enabled\n");
Hans de Goededd3e2022021-08-02 16:24:57 +0200148 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT)
149 dev_info(dev, "quirk LINEOUT enabled\n");
Hans de Goede044c7652021-08-02 16:24:59 +0200150 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT_AS_HP2)
151 dev_info(dev, "quirk LINEOUT_AS_HP2 enabled\n");
Hans de Goedea3ad2912018-05-13 09:24:26 +0200152 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
153 dev_info(dev, "quirk DIFF_MIC enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500154 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
155 dev_info(dev, "quirk SSP0_AIF1 enabled\n");
156 has_ssp0 = true;
157 has_ssp0_aif1 = true;
158 }
159 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
160 dev_info(dev, "quirk SSP0_AIF2 enabled\n");
161 has_ssp0 = true;
162 has_ssp0_aif2 = true;
163 }
164 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
165 dev_info(dev, "quirk SSP2_AIF2 enabled\n");
166 has_ssp2_aif2 = true;
167 }
168 if (is_bytcr && !has_ssp0)
169 dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2 on bytcr\n");
170 if (has_ssp0_aif1 && has_ssp0_aif2)
171 dev_err(dev, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n");
172 if (has_ssp0 && has_ssp2_aif2)
173 dev_err(dev, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n");
174
175 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
176 dev_info(dev, "quirk MCLK_EN enabled\n");
177 has_mclk = true;
178 }
179 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
180 if (has_mclk)
181 dev_info(dev, "quirk MCLK_25MHZ enabled\n");
182 else
183 dev_err(dev, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n");
184 }
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500185}
186
Hans de Goedebcd9a322018-05-08 17:35:53 +0200187static int byt_rt5640_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai,
188 int rate)
189{
190 int ret;
191
192 /* Configure the PLL before selecting it */
193 if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) {
194 /* use bitclock as PLL input */
195 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
196 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
197 /* 2x16 bit slots on SSP0 */
198 ret = snd_soc_dai_set_pll(codec_dai, 0,
199 RT5640_PLL1_S_BCLK1,
200 rate * 32, rate * 512);
201 } else {
202 /* 2x15 bit slots on SSP2 */
203 ret = snd_soc_dai_set_pll(codec_dai, 0,
204 RT5640_PLL1_S_BCLK1,
205 rate * 50, rate * 512);
206 }
207 } else {
208 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
209 ret = snd_soc_dai_set_pll(codec_dai, 0,
210 RT5640_PLL1_S_MCLK,
211 25000000, rate * 512);
212 } else {
213 ret = snd_soc_dai_set_pll(codec_dai, 0,
214 RT5640_PLL1_S_MCLK,
215 19200000, rate * 512);
216 }
217 }
218
219 if (ret < 0) {
Hans de Goedea3a956a2018-05-11 11:52:16 +0200220 dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret);
Hans de Goedebcd9a322018-05-08 17:35:53 +0200221 return ret;
222 }
223
224 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
225 rate * 512, SND_SOC_CLOCK_IN);
226 if (ret < 0) {
Hans de Goedea3a956a2018-05-11 11:52:16 +0200227 dev_err(codec_dai->component->dev, "can't set clock %d\n", ret);
Hans de Goedebcd9a322018-05-08 17:35:53 +0200228 return ret;
229 }
230
231 return 0;
232}
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500233
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500234#define BYT_CODEC_DAI1 "rt5640-aif1"
235#define BYT_CODEC_DAI2 "rt5640-aif2"
236
Hans de Goede81071142021-08-02 16:24:58 +0200237static struct snd_soc_dai *byt_rt5640_get_codec_dai(struct snd_soc_dapm_context *dapm)
238{
239 struct snd_soc_card *card = dapm->card;
240 struct snd_soc_dai *codec_dai;
241
242 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1);
243 if (!codec_dai)
244 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2);
245 if (!codec_dai)
246 dev_err(card->dev, "Error codec dai not found\n");
247
248 return codec_dai;
249}
250
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500251static int platform_clock_control(struct snd_soc_dapm_widget *w,
252 struct snd_kcontrol *k, int event)
253{
254 struct snd_soc_dapm_context *dapm = w->dapm;
255 struct snd_soc_card *card = dapm->card;
256 struct snd_soc_dai *codec_dai;
257 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
258 int ret;
259
Hans de Goede81071142021-08-02 16:24:58 +0200260 codec_dai = byt_rt5640_get_codec_dai(dapm);
Pierre-Louis Bossartdfb6ec72017-10-12 18:38:03 -0500261 if (!codec_dai)
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500262 return -EIO;
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500263
264 if (SND_SOC_DAPM_EVENT_ON(event)) {
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500265 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500266 ret = clk_prepare_enable(priv->mclk);
267 if (ret < 0) {
268 dev_err(card->dev,
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500269 "could not configure MCLK state\n");
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500270 return ret;
271 }
272 }
Hans de Goedebcd9a322018-05-08 17:35:53 +0200273 ret = byt_rt5640_prepare_and_enable_pll1(codec_dai, 48000);
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500274 } else {
275 /*
276 * Set codec clock source to internal clock before
277 * turning off the platform clock. Codec needs clock
278 * for Jack detection and button press
279 */
280 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK,
Pierre-Louis Bossart60448b02017-01-04 15:44:52 -0600281 48000 * 512,
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500282 SND_SOC_CLOCK_IN);
283 if (!ret) {
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500284 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500285 clk_disable_unprepare(priv->mclk);
286 }
287 }
288
289 if (ret < 0) {
290 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
291 return ret;
292 }
293
294 return 0;
295}
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -0600296
Hans de Goede044c7652021-08-02 16:24:59 +0200297static int byt_rt5640_event_lineout(struct snd_soc_dapm_widget *w,
298 struct snd_kcontrol *k, int event)
299{
300 unsigned int gpio_ctrl3_val = RT5640_GP1_PF_OUT;
301 struct snd_soc_dai *codec_dai;
302
303 if (!(byt_rt5640_quirk & BYT_RT5640_LINEOUT_AS_HP2))
304 return 0;
305
306 /*
307 * On devices which use line-out as a second headphones output,
308 * the codec's GPIO1 pin is used to enable an external HP-amp.
309 */
310
311 codec_dai = byt_rt5640_get_codec_dai(w->dapm);
312 if (!codec_dai)
313 return -EIO;
314
315 if (SND_SOC_DAPM_EVENT_ON(event))
316 gpio_ctrl3_val |= RT5640_GP1_OUT_HI;
317
318 snd_soc_component_update_bits(codec_dai->component, RT5640_GPIO_CTRL3,
319 RT5640_GP1_PF_MASK | RT5640_GP1_OUT_MASK, gpio_ctrl3_val);
320
321 return 0;
322}
323
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600324static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530325 SND_SOC_DAPM_HP("Headphone", NULL),
326 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600327 SND_SOC_DAPM_MIC("Internal Mic", NULL),
328 SND_SOC_DAPM_SPK("Speaker", NULL),
Hans de Goede044c7652021-08-02 16:24:59 +0200329 SND_SOC_DAPM_LINE("Line Out", byt_rt5640_event_lineout),
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500330 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
331 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
332 SND_SOC_DAPM_POST_PMD),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530333};
334
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600335static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500336 {"Headphone", NULL, "Platform Clock"},
337 {"Headset Mic", NULL, "Platform Clock"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530338 {"Headset Mic", NULL, "MICBIAS1"},
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600339 {"IN2P", NULL, "Headset Mic"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530340 {"Headphone", NULL, "HPOL"},
341 {"Headphone", NULL, "HPOR"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530342};
343
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600344static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
Hans de Goededccd1df2021-08-02 16:24:56 +0200345 {"Internal Mic", NULL, "Platform Clock"},
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600346 {"DMIC1", NULL, "Internal Mic"},
347};
348
349static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
Hans de Goededccd1df2021-08-02 16:24:56 +0200350 {"Internal Mic", NULL, "Platform Clock"},
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600351 {"DMIC2", NULL, "Internal Mic"},
352};
353
354static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
Hans de Goededccd1df2021-08-02 16:24:56 +0200355 {"Internal Mic", NULL, "Platform Clock"},
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600356 {"Internal Mic", NULL, "MICBIAS1"},
357 {"IN1P", NULL, "Internal Mic"},
358};
359
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -0500360static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
Hans de Goededccd1df2021-08-02 16:24:56 +0200361 {"Internal Mic", NULL, "Platform Clock"},
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -0500362 {"Internal Mic", NULL, "MICBIAS1"},
363 {"IN3P", NULL, "Internal Mic"},
364};
365
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500366static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
367 {"ssp2 Tx", NULL, "codec_out0"},
368 {"ssp2 Tx", NULL, "codec_out1"},
369 {"codec_in0", NULL, "ssp2 Rx"},
370 {"codec_in1", NULL, "ssp2 Rx"},
371
372 {"AIF1 Playback", NULL, "ssp2 Tx"},
373 {"ssp2 Rx", NULL, "AIF1 Capture"},
374};
375
376static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
377 {"ssp2 Tx", NULL, "codec_out0"},
378 {"ssp2 Tx", NULL, "codec_out1"},
379 {"codec_in0", NULL, "ssp2 Rx"},
380 {"codec_in1", NULL, "ssp2 Rx"},
381
382 {"AIF2 Playback", NULL, "ssp2 Tx"},
383 {"ssp2 Rx", NULL, "AIF2 Capture"},
384};
385
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500386static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
387 {"ssp0 Tx", NULL, "modem_out"},
388 {"modem_in", NULL, "ssp0 Rx"},
389
390 {"AIF1 Playback", NULL, "ssp0 Tx"},
391 {"ssp0 Rx", NULL, "AIF1 Capture"},
392};
393
394static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
395 {"ssp0 Tx", NULL, "modem_out"},
396 {"modem_in", NULL, "ssp0 Rx"},
397
398 {"AIF2 Playback", NULL, "ssp0 Tx"},
399 {"ssp0 Rx", NULL, "AIF2 Capture"},
400};
401
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500402static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
Hans de Goededccd1df2021-08-02 16:24:56 +0200403 {"Speaker", NULL, "Platform Clock"},
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500404 {"Speaker", NULL, "SPOLP"},
405 {"Speaker", NULL, "SPOLN"},
406 {"Speaker", NULL, "SPORP"},
407 {"Speaker", NULL, "SPORN"},
408};
409
410static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
Hans de Goededccd1df2021-08-02 16:24:56 +0200411 {"Speaker", NULL, "Platform Clock"},
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500412 {"Speaker", NULL, "SPOLP"},
413 {"Speaker", NULL, "SPOLN"},
414};
415
Hans de Goededd3e2022021-08-02 16:24:57 +0200416static const struct snd_soc_dapm_route byt_rt5640_lineout_map[] = {
417 {"Line Out", NULL, "Platform Clock"},
418 {"Line Out", NULL, "LOUTR"},
419 {"Line Out", NULL, "LOUTL"},
420};
421
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600422static const struct snd_kcontrol_new byt_rt5640_controls[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530423 SOC_DAPM_PIN_SWITCH("Headphone"),
424 SOC_DAPM_PIN_SWITCH("Headset Mic"),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600425 SOC_DAPM_PIN_SWITCH("Internal Mic"),
426 SOC_DAPM_PIN_SWITCH("Speaker"),
Hans de Goededd3e2022021-08-02 16:24:57 +0200427 SOC_DAPM_PIN_SWITCH("Line Out"),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530428};
429
Hans de Goede77323102018-05-13 09:24:28 +0200430static struct snd_soc_jack_pin rt5640_pins[] = {
431 {
432 .pin = "Headphone",
433 .mask = SND_JACK_HEADPHONE,
434 },
435 {
436 .pin = "Headset Mic",
437 .mask = SND_JACK_MICROPHONE,
438 },
439};
440
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600441static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530442 struct snd_pcm_hw_params *params)
443{
Kuninori Morimoto2207b932020-07-27 10:08:29 +0900444 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +0900445 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530446
Hans de Goedebcd9a322018-05-08 17:35:53 +0200447 return byt_rt5640_prepare_and_enable_pll1(dai, params_rate(params));
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530448}
449
Hans de Goede3c0d0112018-05-13 09:24:32 +0200450/* Please keep this list alphabetically sorted */
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600451static const struct dmi_system_id byt_rt5640_quirk_table[] = {
Hans de Goedeec8e8412018-05-13 09:24:34 +0200452 { /* Acer Iconia Tab 8 W1-810 */
453 .matches = {
454 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
455 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
456 },
457 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
458 BYT_RT5640_JD_SRC_JD1_IN4P |
Hans de Goedef12a0a32018-06-03 15:42:32 +0200459 BYT_RT5640_OVCD_TH_1500UA |
Hans de Goedeec8e8412018-05-13 09:24:34 +0200460 BYT_RT5640_OVCD_SF_0P75 |
461 BYT_RT5640_SSP0_AIF1 |
462 BYT_RT5640_MCLK_EN),
463 },
Hans de Goedec58947a2021-02-16 22:35:55 +0100464 { /* Acer One 10 S1002 */
465 .matches = {
466 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
467 DMI_MATCH(DMI_PRODUCT_NAME, "One S1002"),
468 },
469 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
470 BYT_RT5640_JD_SRC_JD2_IN4N |
471 BYT_RT5640_OVCD_TH_2000UA |
472 BYT_RT5640_OVCD_SF_0P75 |
473 BYT_RT5640_DIFF_MIC |
474 BYT_RT5640_SSP0_AIF2 |
475 BYT_RT5640_MCLK_EN),
476 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600477 {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600478 .matches = {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200479 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
480 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
481 },
Hans de Goede0bb88772019-11-19 15:51:38 +0100482 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
483 BYT_RT5640_JD_SRC_JD2_IN4N |
484 BYT_RT5640_OVCD_TH_2000UA |
485 BYT_RT5640_OVCD_SF_0P75 |
486 BYT_RT5640_SSP0_AIF1 |
487 BYT_RT5640_MCLK_EN),
Hans de Goede3c0d0112018-05-13 09:24:32 +0200488 },
489 {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200490 .matches = {
Hans de Goedebcf441a2018-05-28 22:26:49 +0200491 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
492 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 80 Cesium"),
493 },
494 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
495 BYT_RT5640_MONO_SPEAKER |
496 BYT_RT5640_SSP0_AIF1 |
497 BYT_RT5640_MCLK_EN),
498 },
499 {
500 .matches = {
Chris Chiu1bea2252020-12-08 14:04:14 +0800501 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
502 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 140 CESIUM"),
503 },
504 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
505 BYT_RT5640_JD_SRC_JD2_IN4N |
506 BYT_RT5640_OVCD_TH_2000UA |
507 BYT_RT5640_OVCD_SF_0P75 |
508 BYT_RT5640_SSP0_AIF1 |
509 BYT_RT5640_MCLK_EN),
510 },
511 {
512 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500513 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
Stephan Gerhold51a13e42019-01-02 20:39:08 +0100514 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
515 },
516 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
517 BYT_RT5640_JD_SRC_JD2_IN4N |
518 BYT_RT5640_OVCD_TH_2000UA |
519 BYT_RT5640_OVCD_SF_0P75 |
520 BYT_RT5640_SSP0_AIF1 |
521 BYT_RT5640_MCLK_EN),
522 },
523 {
524 .matches = {
525 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500526 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600527 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500528 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
Hans de Goede77323102018-05-13 09:24:28 +0200529 BYT_RT5640_JD_SRC_JD2_IN4N |
530 BYT_RT5640_OVCD_TH_2000UA |
531 BYT_RT5640_OVCD_SF_0P75 |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500532 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600533 },
534 {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600535 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500536 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
537 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
538 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500539 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
Hans de Goedeb7c72032021-03-12 12:48:50 +0100540 BYT_RT5640_JD_SRC_JD2_IN4N |
541 BYT_RT5640_OVCD_TH_2000UA |
542 BYT_RT5640_OVCD_SF_0P75 |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500543 BYT_RT5640_MONO_SPEAKER |
544 BYT_RT5640_DIFF_MIC |
545 BYT_RT5640_SSP0_AIF2 |
546 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500547 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200548 { /* Chuwi Vi8 (CWI506) */
549 .matches = {
550 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"),
551 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "i86"),
552 /* The above are too generic, also match BIOS info */
553 DMI_MATCH(DMI_BIOS_VERSION, "CHUWI.D86JLBNR"),
554 },
555 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
556 BYT_RT5640_MONO_SPEAKER |
557 BYT_RT5640_SSP0_AIF1 |
558 BYT_RT5640_MCLK_EN),
559 },
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500560 {
Hans de Goeded5a18262018-06-08 10:19:25 +0200561 /* Chuwi Vi10 (CWI505) */
562 .matches = {
563 DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
564 DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"),
565 DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
566 DMI_MATCH(DMI_PRODUCT_NAME, "S165"),
567 },
568 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
569 BYT_RT5640_JD_SRC_JD2_IN4N |
570 BYT_RT5640_OVCD_TH_2000UA |
571 BYT_RT5640_OVCD_SF_0P75 |
572 BYT_RT5640_DIFF_MIC |
573 BYT_RT5640_SSP0_AIF1 |
574 BYT_RT5640_MCLK_EN),
575 },
576 {
Hans de Goede875c40e2021-03-25 23:10:54 +0100577 /* Chuwi Hi8 (CWI509) */
578 .matches = {
579 DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
580 DMI_MATCH(DMI_BOARD_NAME, "BYT-PA03C"),
581 DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
582 DMI_MATCH(DMI_PRODUCT_NAME, "S806"),
583 },
584 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
585 BYT_RT5640_JD_SRC_JD2_IN4N |
586 BYT_RT5640_OVCD_TH_2000UA |
587 BYT_RT5640_OVCD_SF_0P75 |
588 BYT_RT5640_MONO_SPEAKER |
589 BYT_RT5640_DIFF_MIC |
590 BYT_RT5640_SSP0_AIF1 |
591 BYT_RT5640_MCLK_EN),
592 },
593 {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500594 .matches = {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200595 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
596 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
597 },
598 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP),
599 },
Hans de Goede9ee6f8a2018-07-01 11:30:23 +0200600 { /* Connect Tablet 9 */
601 .matches = {
602 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Connect"),
603 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Tablet 9"),
604 },
605 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
606 BYT_RT5640_MONO_SPEAKER |
607 BYT_RT5640_SSP0_AIF1 |
608 BYT_RT5640_MCLK_EN),
609 },
Hans de Goede3c0d0112018-05-13 09:24:32 +0200610 {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200611 .matches = {
Hans de Goede6748fb72018-05-13 09:24:27 +0200612 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500613 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600614 },
Hans de Goede6748fb72018-05-13 09:24:27 +0200615 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
Hans de Goede77323102018-05-13 09:24:28 +0200616 BYT_RT5640_JD_SRC_JD2_IN4N |
617 BYT_RT5640_OVCD_TH_2000UA |
618 BYT_RT5640_OVCD_SF_0P75 |
Hans de Goede6748fb72018-05-13 09:24:27 +0200619 BYT_RT5640_MONO_SPEAKER |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500620 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600621 },
Hans de Goedebdea43f2021-02-16 22:35:52 +0100622 { /* Estar Beauty HD MID 7316R */
623 .matches = {
624 DMI_MATCH(DMI_SYS_VENDOR, "Estar"),
625 DMI_MATCH(DMI_PRODUCT_NAME, "eSTAR BEAUTY HD Intel Quad core"),
626 },
627 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
628 BYT_RT5640_MONO_SPEAKER |
629 BYT_RT5640_SSP0_AIF1 |
630 BYT_RT5640_MCLK_EN),
631 },
Hans de Goede28c268d2021-05-08 17:01:45 +0200632 { /* Glavey TM800A550L */
633 .matches = {
634 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
635 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
636 /* Above strings are too generic, also match on BIOS version */
637 DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
638 },
639 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
640 BYT_RT5640_SSP0_AIF1 |
641 BYT_RT5640_MCLK_EN),
642 },
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600643 {
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600644 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500645 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
646 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600647 },
Hans de Goede780feaf2021-08-02 16:25:01 +0200648 .driver_data = (void *)(BYT_RT5640_DMIC2_MAP |
649 BYT_RT5640_MCLK_EN |
650 BYT_RT5640_LINEOUT |
651 BYT_RT5640_LINEOUT_AS_HP2 |
652 BYT_RT5640_HSMIC2_ON_IN1),
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600653 },
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100654 { /* HP Pavilion x2 10-k0XX, 10-n0XX */
Hans de Goedeec8e8412018-05-13 09:24:34 +0200655 .matches = {
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100656 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
657 DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion x2 Detachable"),
Hans de Goedeec8e8412018-05-13 09:24:34 +0200658 },
659 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
660 BYT_RT5640_JD_SRC_JD2_IN4N |
661 BYT_RT5640_OVCD_TH_1500UA |
662 BYT_RT5640_OVCD_SF_0P75 |
663 BYT_RT5640_SSP0_AIF1 |
664 BYT_RT5640_MCLK_EN),
665 },
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100666 { /* HP Pavilion x2 10-p0XX */
667 .matches = {
668 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
669 DMI_MATCH(DMI_PRODUCT_NAME, "HP x2 Detachable 10-p0XX"),
670 },
671 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
672 BYT_RT5640_JD_SRC_JD1_IN4P |
Hans de Goedeca08ddf2021-02-24 11:50:52 +0100673 BYT_RT5640_OVCD_TH_2000UA |
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100674 BYT_RT5640_OVCD_SF_0P75 |
675 BYT_RT5640_MCLK_EN),
676 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200677 { /* HP Stream 7 */
678 .matches = {
679 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
680 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Stream 7 Tablet"),
681 },
682 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
683 BYT_RT5640_MONO_SPEAKER |
684 BYT_RT5640_JD_NOT_INV |
685 BYT_RT5640_SSP0_AIF1 |
686 BYT_RT5640_MCLK_EN),
687 },
688 { /* I.T.Works TW891 */
689 .matches = {
690 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
691 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
692 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
693 DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
694 },
695 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
696 BYT_RT5640_MONO_SPEAKER |
697 BYT_RT5640_SSP0_AIF1 |
698 BYT_RT5640_MCLK_EN),
699 },
700 { /* Lamina I8270 / T701BR.SE */
701 .matches = {
702 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Lamina"),
703 DMI_EXACT_MATCH(DMI_BOARD_NAME, "T701BR.SE"),
704 },
705 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
706 BYT_RT5640_MONO_SPEAKER |
707 BYT_RT5640_JD_NOT_INV |
708 BYT_RT5640_SSP0_AIF1 |
709 BYT_RT5640_MCLK_EN),
710 },
Hans de Goede81583af2018-07-07 12:22:10 +0200711 { /* Lenovo Miix 2 8 */
712 .matches = {
713 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
714 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "20326"),
715 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Hiking"),
716 },
717 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
718 BYT_RT5640_JD_SRC_JD2_IN4N |
719 BYT_RT5640_OVCD_TH_2000UA |
720 BYT_RT5640_OVCD_SF_0P75 |
721 BYT_RT5640_MONO_SPEAKER |
722 BYT_RT5640_MCLK_EN),
723 },
Hans de Goedef0353e12021-05-08 17:01:46 +0200724 { /* Lenovo Miix 3-830 */
725 .matches = {
726 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
727 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 3-830"),
728 },
729 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
730 BYT_RT5640_JD_SRC_JD2_IN4N |
731 BYT_RT5640_OVCD_TH_2000UA |
732 BYT_RT5640_OVCD_SF_0P75 |
733 BYT_RT5640_MONO_SPEAKER |
734 BYT_RT5640_DIFF_MIC |
735 BYT_RT5640_SSP0_AIF1 |
736 BYT_RT5640_MCLK_EN),
737 },
Hans de Goede260c48b2018-08-12 13:42:06 +0200738 { /* Linx Linx7 tablet */
739 .matches = {
740 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LINX"),
741 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LINX7"),
742 },
743 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
744 BYT_RT5640_MONO_SPEAKER |
745 BYT_RT5640_JD_NOT_INV |
746 BYT_RT5640_SSP0_AIF1 |
747 BYT_RT5640_MCLK_EN),
748 },
Hans de Goededf330322021-01-09 22:01:19 +0100749 { /* Mele PCG03 Mini PC */
750 .matches = {
751 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Mini PC"),
752 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Mini PC"),
753 },
754 .driver_data = (void *)(BYT_RT5640_NO_INTERNAL_MIC_MAP |
755 BYT_RT5640_NO_SPEAKERS |
756 BYT_RT5640_SSP0_AIF1),
757 },
Hans de Goede6a013712020-09-01 10:06:23 +0200758 { /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */
759 .matches = {
760 DMI_MATCH(DMI_SYS_VENDOR, "MPMAN"),
761 DMI_MATCH(DMI_PRODUCT_NAME, "Converter9"),
762 },
763 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
764 BYT_RT5640_MONO_SPEAKER |
765 BYT_RT5640_SSP0_AIF1 |
766 BYT_RT5640_MCLK_EN),
767 },
Hans de Goedec8b78f22020-04-05 15:37:26 +0200768 {
769 /* MPMAN MPWIN895CL */
770 .matches = {
771 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MPMAN"),
772 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MPWIN8900CL"),
773 },
774 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
775 BYT_RT5640_MONO_SPEAKER |
776 BYT_RT5640_SSP0_AIF1 |
777 BYT_RT5640_MCLK_EN),
778 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200779 { /* MSI S100 tablet */
780 .matches = {
781 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
782 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "S100"),
783 },
784 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
785 BYT_RT5640_JD_SRC_JD2_IN4N |
786 BYT_RT5640_OVCD_TH_2000UA |
787 BYT_RT5640_OVCD_SF_0P75 |
788 BYT_RT5640_MONO_SPEAKER |
789 BYT_RT5640_DIFF_MIC |
790 BYT_RT5640_MCLK_EN),
791 },
Hans de Goede6cea3592018-06-03 15:42:31 +0200792 { /* Nuvison/TMax TM800W560 */
793 .matches = {
794 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TMAX"),
795 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TM800W560L"),
796 },
797 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
798 BYT_RT5640_JD_SRC_JD2_IN4N |
799 BYT_RT5640_OVCD_TH_2000UA |
800 BYT_RT5640_OVCD_SF_0P75 |
801 BYT_RT5640_JD_NOT_INV |
802 BYT_RT5640_DIFF_MIC |
803 BYT_RT5640_SSP0_AIF1 |
804 BYT_RT5640_MCLK_EN),
805 },
Hans de Goede260c48b2018-08-12 13:42:06 +0200806 { /* Onda v975w */
807 .matches = {
808 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
809 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
810 /* The above are too generic, also match BIOS info */
811 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "5.6.5"),
812 DMI_EXACT_MATCH(DMI_BIOS_DATE, "07/25/2014"),
813 },
814 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
815 BYT_RT5640_JD_SRC_JD2_IN4N |
816 BYT_RT5640_OVCD_TH_2000UA |
817 BYT_RT5640_OVCD_SF_0P75 |
818 BYT_RT5640_DIFF_MIC |
819 BYT_RT5640_MCLK_EN),
820 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200821 { /* Pipo W4 */
822 .matches = {
823 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
824 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
825 /* The above are too generic, also match BIOS info */
826 DMI_MATCH(DMI_BIOS_VERSION, "V8L_WIN32_CHIPHD"),
827 },
828 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
829 BYT_RT5640_MONO_SPEAKER |
830 BYT_RT5640_SSP0_AIF1 |
831 BYT_RT5640_MCLK_EN),
832 },
833 { /* Point of View Mobii TAB-P800W (V2.0) */
834 .matches = {
835 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
836 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
837 /* The above are too generic, also match BIOS info */
838 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1014"),
839 DMI_EXACT_MATCH(DMI_BIOS_DATE, "10/24/2014"),
840 },
841 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
842 BYT_RT5640_JD_SRC_JD2_IN4N |
843 BYT_RT5640_OVCD_TH_2000UA |
844 BYT_RT5640_OVCD_SF_0P75 |
845 BYT_RT5640_MONO_SPEAKER |
846 BYT_RT5640_DIFF_MIC |
847 BYT_RT5640_SSP0_AIF2 |
848 BYT_RT5640_MCLK_EN),
849 },
850 { /* Point of View Mobii TAB-P800W (V2.1) */
851 .matches = {
852 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
853 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
854 /* The above are too generic, also match BIOS info */
855 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1013"),
856 DMI_EXACT_MATCH(DMI_BIOS_DATE, "08/22/2014"),
857 },
858 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
859 BYT_RT5640_JD_SRC_JD2_IN4N |
860 BYT_RT5640_OVCD_TH_2000UA |
861 BYT_RT5640_OVCD_SF_0P75 |
862 BYT_RT5640_MONO_SPEAKER |
863 BYT_RT5640_DIFF_MIC |
864 BYT_RT5640_SSP0_AIF2 |
865 BYT_RT5640_MCLK_EN),
866 },
Hans de Goede02e5af62018-12-08 14:01:14 +0100867 { /* Point of View Mobii TAB-P1005W-232 (V2.0) */
868 .matches = {
869 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "POV"),
870 DMI_EXACT_MATCH(DMI_BOARD_NAME, "I102A"),
871 },
872 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
873 BYT_RT5640_JD_SRC_JD2_IN4N |
874 BYT_RT5640_OVCD_TH_2000UA |
875 BYT_RT5640_OVCD_SF_0P75 |
876 BYT_RT5640_DIFF_MIC |
877 BYT_RT5640_SSP0_AIF1 |
878 BYT_RT5640_MCLK_EN),
879 },
Irina Tirdea0565e772016-08-12 16:27:58 -0500880 {
Hans de Goede271248f2018-12-08 14:01:13 +0100881 /* Prowise PT301 */
882 .matches = {
883 DMI_MATCH(DMI_SYS_VENDOR, "Prowise"),
884 DMI_MATCH(DMI_PRODUCT_NAME, "PT301"),
885 },
886 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
887 BYT_RT5640_JD_SRC_JD2_IN4N |
888 BYT_RT5640_OVCD_TH_2000UA |
889 BYT_RT5640_OVCD_SF_0P75 |
890 BYT_RT5640_DIFF_MIC |
891 BYT_RT5640_SSP0_AIF1 |
892 BYT_RT5640_MCLK_EN),
893 },
894 {
Hans de Goede7eccc052019-12-03 23:14:42 +0100895 /* Teclast X89 */
Irina Tirdea0565e772016-08-12 16:27:58 -0500896 .matches = {
Pierre-Louis Bossartec1c90e2016-08-12 16:27:59 -0500897 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
898 DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
899 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500900 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
Hans de Goede7eccc052019-12-03 23:14:42 +0100901 BYT_RT5640_JD_SRC_JD1_IN4P |
902 BYT_RT5640_OVCD_TH_2000UA |
903 BYT_RT5640_OVCD_SF_1P0 |
904 BYT_RT5640_SSP0_AIF1 |
905 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossartec1c90e2016-08-12 16:27:59 -0500906 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200907 { /* Toshiba Satellite Click Mini L9W-B */
908 .matches = {
909 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
910 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
911 },
912 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
913 BYT_RT5640_JD_SRC_JD2_IN4N |
914 BYT_RT5640_OVCD_TH_1500UA |
915 BYT_RT5640_OVCD_SF_0P75 |
916 BYT_RT5640_SSP0_AIF1 |
917 BYT_RT5640_MCLK_EN),
918 },
Hans de Goede0e0e10f2020-05-18 09:24:16 +0200919 { /* Toshiba Encore WT8-A */
920 .matches = {
921 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
922 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"),
923 },
924 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
925 BYT_RT5640_JD_SRC_JD2_IN4N |
926 BYT_RT5640_OVCD_TH_2000UA |
927 BYT_RT5640_OVCD_SF_0P75 |
928 BYT_RT5640_JD_NOT_INV |
929 BYT_RT5640_MCLK_EN),
930 },
Hans de Goede199a5e82020-06-08 22:46:33 +0200931 { /* Toshiba Encore WT10-A */
932 .matches = {
933 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
934 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"),
935 },
936 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
937 BYT_RT5640_JD_SRC_JD1_IN4P |
938 BYT_RT5640_OVCD_TH_2000UA |
939 BYT_RT5640_OVCD_SF_0P75 |
940 BYT_RT5640_SSP0_AIF2 |
941 BYT_RT5640_MCLK_EN),
942 },
Hans de Goedee1317cc2021-02-16 22:35:53 +0100943 { /* Voyo Winpad A15 */
944 .matches = {
945 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
946 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
947 /* Above strings are too generic, also match on BIOS date */
948 DMI_MATCH(DMI_BIOS_DATE, "11/20/2014"),
949 },
950 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
951 BYT_RT5640_JD_SRC_JD2_IN4N |
952 BYT_RT5640_OVCD_TH_2000UA |
953 BYT_RT5640_OVCD_SF_0P75 |
954 BYT_RT5640_DIFF_MIC |
955 BYT_RT5640_MCLK_EN),
956 },
Hans de Goede3c0d0112018-05-13 09:24:32 +0200957 { /* Catch-all for generic Insyde tablets, must be last */
youling25757180042017-01-04 15:44:53 -0600958 .matches = {
959 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
960 },
Hans de Goede96a388fe2018-05-13 09:24:30 +0200961 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500962 BYT_RT5640_MCLK_EN |
963 BYT_RT5640_SSP0_AIF1),
youling25757180042017-01-04 15:44:53 -0600964
965 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600966 {}
967};
968
Hans de Goede6a7c05e2018-05-08 17:35:54 +0200969/*
970 * Note this MUST be called before snd_soc_register_card(), so that the props
971 * are in place before the codec component driver's probe function parses them.
972 */
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -0500973static int byt_rt5640_add_codec_device_props(struct device *i2c_dev,
974 struct byt_rt5640_private *priv)
Hans de Goede6a7c05e2018-05-08 17:35:54 +0200975{
976 struct property_entry props[MAX_NO_PROPS] = {};
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -0500977 int cnt = 0;
Hans de Goede6a7c05e2018-05-08 17:35:54 +0200978
979 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
Hans de Goedea3ad2912018-05-13 09:24:26 +0200980 case BYT_RT5640_DMIC1_MAP:
981 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin",
982 RT5640_DMIC1_DATA_PIN_IN1P);
983 break;
984 case BYT_RT5640_DMIC2_MAP:
985 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin",
986 RT5640_DMIC2_DATA_PIN_IN1N);
987 break;
Hans de Goede6a7c05e2018-05-08 17:35:54 +0200988 case BYT_RT5640_IN1_MAP:
989 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
990 props[cnt++] =
991 PROPERTY_ENTRY_BOOL("realtek,in1-differential");
992 break;
993 case BYT_RT5640_IN3_MAP:
994 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
995 props[cnt++] =
996 PROPERTY_ENTRY_BOOL("realtek,in3-differential");
997 break;
998 }
999
Hans de Goede77323102018-05-13 09:24:28 +02001000 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
1001 props[cnt++] = PROPERTY_ENTRY_U32(
1002 "realtek,jack-detect-source",
1003 BYT_RT5640_JDSRC(byt_rt5640_quirk));
1004
1005 props[cnt++] = PROPERTY_ENTRY_U32(
1006 "realtek,over-current-threshold-microamp",
1007 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
1008
1009 props[cnt++] = PROPERTY_ENTRY_U32(
1010 "realtek,over-current-scale-factor",
1011 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
1012 }
1013
1014 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
1015 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted");
1016
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001017 return device_add_properties(i2c_dev, props);
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001018}
1019
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001020static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
1021{
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001022 struct snd_soc_card *card = runtime->card;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001023 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +09001024 struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
Hans de Goede46466ab2021-01-09 22:01:18 +01001025 const struct snd_soc_dapm_route *custom_map = NULL;
1026 int num_routes = 0;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001027 int ret;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001028
1029 card->dapm.idle_bias_off = true;
1030
Hans de Goede77323102018-05-13 09:24:28 +02001031 /* Start with RC clk for jack-detect (we disable MCLK below) */
1032 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
1033 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
1034 RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_RCCLK);
1035
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001036 rt5640_sel_asrc_clk_src(component,
Pierre-Louis Bossart0ec66e2d2016-01-04 17:20:27 -06001037 RT5640_DA_STEREO_FILTER |
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001038 RT5640_DA_MONO_L_FILTER |
1039 RT5640_DA_MONO_R_FILTER |
1040 RT5640_AD_STEREO_FILTER |
1041 RT5640_AD_MONO_L_FILTER |
1042 RT5640_AD_MONO_R_FILTER,
Pierre-Louis Bossart0ec66e2d2016-01-04 17:20:27 -06001043 RT5640_CLK_SEL_ASRC);
1044
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001045 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
1046 ARRAY_SIZE(byt_rt5640_controls));
1047 if (ret) {
1048 dev_err(card->dev, "unable to add card controls\n");
1049 return ret;
1050 }
1051
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001052 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
1053 case BYT_RT5640_IN1_MAP:
1054 custom_map = byt_rt5640_intmic_in1_map;
1055 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
1056 break;
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -05001057 case BYT_RT5640_IN3_MAP:
1058 custom_map = byt_rt5640_intmic_in3_map;
1059 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
1060 break;
Hans de Goede46466ab2021-01-09 22:01:18 +01001061 case BYT_RT5640_DMIC1_MAP:
1062 custom_map = byt_rt5640_intmic_dmic1_map;
1063 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
1064 break;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001065 case BYT_RT5640_DMIC2_MAP:
1066 custom_map = byt_rt5640_intmic_dmic2_map;
1067 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
1068 break;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001069 }
1070
1071 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
1072 if (ret)
1073 return ret;
1074
Hans de Goede79c1123b2021-08-02 16:25:00 +02001075 if (byt_rt5640_quirk & BYT_RT5640_HSMIC2_ON_IN1) {
1076 ret = snd_soc_dapm_add_routes(&card->dapm,
1077 byt_rt5640_intmic_in1_map,
1078 ARRAY_SIZE(byt_rt5640_intmic_in1_map));
1079 if (ret)
1080 return ret;
1081 }
1082
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -05001083 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
1084 ret = snd_soc_dapm_add_routes(&card->dapm,
1085 byt_rt5640_ssp2_aif2_map,
1086 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001087 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
1088 ret = snd_soc_dapm_add_routes(&card->dapm,
1089 byt_rt5640_ssp0_aif1_map,
1090 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
1091 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
1092 ret = snd_soc_dapm_add_routes(&card->dapm,
1093 byt_rt5640_ssp0_aif2_map,
1094 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -05001095 } else {
1096 ret = snd_soc_dapm_add_routes(&card->dapm,
1097 byt_rt5640_ssp2_aif1_map,
1098 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
1099 }
1100 if (ret)
1101 return ret;
1102
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -05001103 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1104 ret = snd_soc_dapm_add_routes(&card->dapm,
1105 byt_rt5640_mono_spk_map,
1106 ARRAY_SIZE(byt_rt5640_mono_spk_map));
Hans de Goede1851ccf2021-01-09 22:01:17 +01001107 } else if (!(byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)) {
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -05001108 ret = snd_soc_dapm_add_routes(&card->dapm,
1109 byt_rt5640_stereo_spk_map,
1110 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
1111 }
1112 if (ret)
1113 return ret;
1114
Hans de Goededd3e2022021-08-02 16:24:57 +02001115 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT) {
1116 ret = snd_soc_dapm_add_routes(&card->dapm,
1117 byt_rt5640_lineout_map,
1118 ARRAY_SIZE(byt_rt5640_lineout_map));
1119 if (ret)
1120 return ret;
1121 }
1122
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001123 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001124 /*
1125 * The firmware might enable the clock at
1126 * boot (this information may or may not
1127 * be reflected in the enable clock register).
1128 * To change the rate we must disable the clock
1129 * first to cover these cases. Due to common
1130 * clock framework restrictions that do not allow
1131 * to disable a clock that has not been enabled,
1132 * we need to enable the clock first.
1133 */
1134 ret = clk_prepare_enable(priv->mclk);
1135 if (!ret)
1136 clk_disable_unprepare(priv->mclk);
1137
1138 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
1139 ret = clk_set_rate(priv->mclk, 25000000);
1140 else
1141 ret = clk_set_rate(priv->mclk, 19200000);
1142
Hans de Goede77323102018-05-13 09:24:28 +02001143 if (ret) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001144 dev_err(card->dev, "unable to set MCLK rate\n");
Hans de Goede77323102018-05-13 09:24:28 +02001145 return ret;
1146 }
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001147 }
1148
Hans de Goede77323102018-05-13 09:24:28 +02001149 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
1150 ret = snd_soc_card_jack_new(card, "Headset",
1151 SND_JACK_HEADSET | SND_JACK_BTN_0,
1152 &priv->jack, rt5640_pins,
1153 ARRAY_SIZE(rt5640_pins));
1154 if (ret) {
1155 dev_err(card->dev, "Jack creation failed %d\n", ret);
1156 return ret;
1157 }
1158 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
1159 KEY_PLAYPAUSE);
1160 snd_soc_component_set_jack(component, &priv->jack, NULL);
1161 }
1162
1163 return 0;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001164}
1165
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001166static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301167 struct snd_pcm_hw_params *params)
1168{
1169 struct snd_interval *rate = hw_param_interval(params,
1170 SNDRV_PCM_HW_PARAM_RATE);
1171 struct snd_interval *channels = hw_param_interval(params,
1172 SNDRV_PCM_HW_PARAM_CHANNELS);
Erik Bussing332719b2020-01-15 17:46:16 +01001173 int ret, bits;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301174
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001175 /* The DSP will covert the FE rate to 48k, stereo */
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301176 rate->min = rate->max = 48000;
1177 channels->min = channels->max = 2;
1178
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001179 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
Erik Bussing332719b2020-01-15 17:46:16 +01001180 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
Pierre-Louis Bossart8f98307d2016-08-16 18:28:22 -05001181 /* set SSP0 to 16-bit */
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001182 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
Erik Bussing332719b2020-01-15 17:46:16 +01001183 bits = 16;
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001184 } else {
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001185 /* set SSP2 to 24-bit */
1186 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
Erik Bussing332719b2020-01-15 17:46:16 +01001187 bits = 24;
Sebastien Guiriec3f27ded2015-12-17 20:35:39 -06001188 }
Erik Bussing332719b2020-01-15 17:46:16 +01001189
1190 /*
1191 * Default mode for SSP configuration is TDM 4 slot, override config
1192 * with explicit setting to I2S 2ch. The word length is set with
1193 * dai_set_tdm_slot() since there is no other API exposed
1194 */
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +09001195 ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
Erik Bussing332719b2020-01-15 17:46:16 +01001196 SND_SOC_DAIFMT_I2S |
1197 SND_SOC_DAIFMT_NB_NF |
1198 SND_SOC_DAIFMT_CBS_CFS);
1199 if (ret < 0) {
1200 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
1201 return ret;
1202 }
1203
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +09001204 ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);
Erik Bussing332719b2020-01-15 17:46:16 +01001205 if (ret < 0) {
1206 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
1207 return ret;
1208 }
1209
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301210 return 0;
1211}
1212
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001213static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301214{
Lars-Peter Clausend0a1b662015-10-18 15:39:30 +02001215 return snd_pcm_hw_constraint_single(substream->runtime,
1216 SNDRV_PCM_HW_PARAM_RATE, 48000);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301217}
1218
Julia Lawall9b6fdef2016-10-15 16:55:49 +02001219static const struct snd_soc_ops byt_rt5640_aif1_ops = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001220 .startup = byt_rt5640_aif1_startup,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301221};
1222
Julia Lawall9b6fdef2016-10-15 16:55:49 +02001223static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001224 .hw_params = byt_rt5640_aif1_hw_params,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301225};
1226
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001227SND_SOC_DAILINK_DEF(dummy,
1228 DAILINK_COMP_ARRAY(COMP_DUMMY()));
1229
1230SND_SOC_DAILINK_DEF(media,
1231 DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
1232
1233SND_SOC_DAILINK_DEF(deepbuffer,
1234 DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
1235
1236SND_SOC_DAILINK_DEF(ssp2_port,
1237 /* overwritten for ssp0 routing */
1238 DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
1239SND_SOC_DAILINK_DEF(ssp2_codec,
1240 DAILINK_COMP_ARRAY(COMP_CODEC(
1241 /* overwritten with HID */ "i2c-10EC5640:00",
1242 /* changed w/ quirk */ "rt5640-aif1")));
1243
1244SND_SOC_DAILINK_DEF(platform,
1245 DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
1246
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001247static struct snd_soc_dai_link byt_rt5640_dais[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301248 [MERR_DPCM_AUDIO] = {
1249 .name = "Baytrail Audio Port",
1250 .stream_name = "Baytrail Audio",
Takashi Iwai6e4cac22017-04-24 14:09:55 +02001251 .nonatomic = true,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301252 .dynamic = 1,
1253 .dpcm_playback = 1,
1254 .dpcm_capture = 1,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001255 .ops = &byt_rt5640_aif1_ops,
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001256 SND_SOC_DAILINK_REG(media, dummy, platform),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301257 },
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001258 [MERR_DPCM_DEEP_BUFFER] = {
1259 .name = "Deep-Buffer Audio Port",
1260 .stream_name = "Deep-Buffer Audio",
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001261 .nonatomic = true,
1262 .dynamic = 1,
1263 .dpcm_playback = 1,
1264 .ops = &byt_rt5640_aif1_ops,
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001265 SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001266 },
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301267 /* back ends */
1268 {
1269 .name = "SSP2-Codec",
Pierre-Louis Bossart149f7752017-10-12 18:38:04 -05001270 .id = 0,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301271 .no_pcm = 1,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301272 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
1273 | SND_SOC_DAIFMT_CBS_CFS,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001274 .be_hw_params_fixup = byt_rt5640_codec_fixup,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301275 .dpcm_playback = 1,
1276 .dpcm_capture = 1,
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001277 .init = byt_rt5640_init,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001278 .ops = &byt_rt5640_be_ssp2_ops,
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001279 SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301280 },
1281};
1282
1283/* SoC card */
Hans de Goede77323102018-05-13 09:24:28 +02001284static char byt_rt5640_codec_name[SND_ACPI_I2C_ID_LEN];
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001285#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
Hans de Goede063422c2018-05-13 09:24:35 +02001286static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001287#endif
Hans de Goededd3e2022021-08-02 16:24:57 +02001288static char byt_rt5640_components[64]; /* = "cfg-spk:* cfg-mic:* ..." */
Hans de Goede77323102018-05-13 09:24:28 +02001289
1290static int byt_rt5640_suspend(struct snd_soc_card *card)
1291{
1292 struct snd_soc_component *component;
1293
1294 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1295 return 0;
1296
Kuninori Morimotof70f18f72018-09-18 01:29:55 +00001297 for_each_card_components(card, component) {
Hans de Goede77323102018-05-13 09:24:28 +02001298 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1299 dev_dbg(component->dev, "disabling jack detect before suspend\n");
1300 snd_soc_component_set_jack(component, NULL, NULL);
1301 break;
1302 }
1303 }
1304
1305 return 0;
1306}
1307
1308static int byt_rt5640_resume(struct snd_soc_card *card)
1309{
1310 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1311 struct snd_soc_component *component;
1312
1313 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1314 return 0;
1315
Kuninori Morimotof70f18f72018-09-18 01:29:55 +00001316 for_each_card_components(card, component) {
Hans de Goede77323102018-05-13 09:24:28 +02001317 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1318 dev_dbg(component->dev, "re-enabling jack detect after resume\n");
1319 snd_soc_component_set_jack(component, &priv->jack, NULL);
1320 break;
1321 }
1322 }
1323
1324 return 0;
1325}
1326
Pierre-Louis Bossartb4ecd582020-06-17 11:56:14 -05001327/* use space before codec name to simplify card ID, and simplify driver name */
Pierre-Louis Bossart41656c32020-11-12 16:38:16 -06001328#define SOF_CARD_NAME "bytcht rt5640" /* card name will be 'sof-bytcht rt5640' */
1329#define SOF_DRIVER_NAME "SOF"
1330
Pierre-Louis Bossartb4ecd582020-06-17 11:56:14 -05001331#define CARD_NAME "bytcr-rt5640"
1332#define DRIVER_NAME NULL /* card name will be used for driver name */
Pierre-Louis Bossartb4ecd582020-06-17 11:56:14 -05001333
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001334static struct snd_soc_card byt_rt5640_card = {
Axel Lin54d86972015-08-21 20:59:21 +08001335 .owner = THIS_MODULE,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001336 .dai_link = byt_rt5640_dais,
1337 .num_links = ARRAY_SIZE(byt_rt5640_dais),
1338 .dapm_widgets = byt_rt5640_widgets,
1339 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
1340 .dapm_routes = byt_rt5640_audio_map,
1341 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001342 .fully_routed = true,
Hans de Goede77323102018-05-13 09:24:28 +02001343 .suspend_pre = byt_rt5640_suspend,
1344 .resume_post = byt_rt5640_resume,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301345};
1346
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001347struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
1348 u64 aif_value; /* 1: AIF1, 2: AIF2 */
1349 u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
1350};
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001351
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001352static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301353{
Pierre-Louis Bossart05ff3122020-11-12 16:38:17 -06001354 struct device *dev = &pdev->dev;
Hans de Goede46466ab2021-01-09 22:01:18 +01001355 static const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3", "none" };
Hans de Goede1851ccf2021-01-09 22:01:17 +01001356 __maybe_unused const char *spk_type;
Hans de Goede6d1bfcc2018-05-13 09:24:33 +02001357 const struct dmi_system_id *dmi_id;
Hans de Goede79c1123b2021-08-02 16:25:00 +02001358 const char *headset2_string = "";
Hans de Goededd3e2022021-08-02 16:24:57 +02001359 const char *lineout_string = "";
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001360 struct byt_rt5640_private *priv;
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001361 struct snd_soc_acpi_mach *mach;
Pierre-Louis Bossartbd7661b2019-01-25 14:34:59 -06001362 const char *platform_name;
Andy Shevchenkoa320d892019-03-28 19:17:25 +02001363 struct acpi_device *adev;
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001364 struct device *codec_dev;
Pierre-Louis Bossart41656c32020-11-12 16:38:16 -06001365 bool sof_parent;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001366 int ret_val = 0;
Pierre-Louis Bossart2193eb92017-10-12 18:38:05 -05001367 int dai_index = 0;
Hans de Goede1851ccf2021-01-09 22:01:17 +01001368 int i, cfg_spk;
Hans de Goede9f47c9c2021-03-07 16:05:03 +01001369 int aif;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001370
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -05001371 is_bytcr = false;
Jia-Ju Bai7a3a6322018-04-09 18:47:37 +08001372 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001373 if (!priv)
1374 return -ENOMEM;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301375
1376 /* register the soc card */
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001377 byt_rt5640_card.dev = &pdev->dev;
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001378 mach = byt_rt5640_card.dev->platform_data;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001379 snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001380
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001381 /* fix index of codec dai */
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001382 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001383 if (!strcmp(byt_rt5640_dais[i].codecs->name,
1384 "i2c-10EC5640:00")) {
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001385 dai_index = i;
1386 break;
1387 }
1388 }
1389
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001390 /* fixup codec name based on HID */
Andy Shevchenkoa320d892019-03-28 19:17:25 +02001391 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
1392 if (adev) {
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001393 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
Andy Shevchenkoa320d892019-03-28 19:17:25 +02001394 "i2c-%s", acpi_dev_name(adev));
1395 put_device(&adev->dev);
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001396 byt_rt5640_dais[dai_index].codecs->name = byt_rt5640_codec_name;
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001397 }
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301398
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001399 /*
1400 * swap SSP0 if bytcr is detected
1401 * (will be overridden if DMI quirk is detected)
1402 */
Pierre-Louis Bossart536cfd22019-05-30 06:50:11 -05001403 if (soc_intel_is_byt()) {
Pierre-Louis Bossart3ee1cd42018-11-01 16:34:50 -05001404 if (mach->mach_params.acpi_ipc_irq_index == 0)
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001405 is_bytcr = true;
1406 }
1407
1408 if (is_bytcr) {
1409 /*
1410 * Baytrail CR platforms may have CHAN package in BIOS, try
1411 * to find relevant routing quirk based as done on Windows
1412 * platforms. We have to read the information directly from the
1413 * BIOS, at this stage the card is not created and the links
1414 * with the codec driver/pdata are non-existent
1415 */
1416
1417 struct acpi_chan_package chan_package;
1418
1419 /* format specified: 2 64-bit integers */
1420 struct acpi_buffer format = {sizeof("NN"), "NN"};
1421 struct acpi_buffer state = {0, NULL};
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001422 struct snd_soc_acpi_package_context pkg_ctx;
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001423 bool pkg_found = false;
1424
1425 state.length = sizeof(chan_package);
1426 state.pointer = &chan_package;
1427
1428 pkg_ctx.name = "CHAN";
1429 pkg_ctx.length = 2;
1430 pkg_ctx.format = &format;
1431 pkg_ctx.state = &state;
1432 pkg_ctx.data_valid = false;
1433
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001434 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
1435 &pkg_ctx);
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001436 if (pkg_found) {
1437 if (chan_package.aif_value == 1) {
1438 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
1439 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
1440 } else if (chan_package.aif_value == 2) {
1441 dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n");
1442 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1443 } else {
1444 dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n");
1445 pkg_found = false;
1446 }
1447 }
1448
1449 if (!pkg_found) {
1450 /* no BIOS indications, assume SSP0-AIF2 connection */
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001451 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1452 }
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -06001453
1454 /* change defaults for Baytrail-CR capture */
Hans de Goede96a388fe2018-05-13 09:24:30 +02001455 byt_rt5640_quirk |= BYTCR_INPUT_DEFAULTS;
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -06001456 } else {
Hans de Goede56ff4402018-05-13 09:24:31 +02001457 byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP |
1458 BYT_RT5640_JD_SRC_JD2_IN4N |
1459 BYT_RT5640_OVCD_TH_2000UA |
1460 BYT_RT5640_OVCD_SF_0P75;
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001461 }
1462
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -06001463 /* check quirks before creating card */
Hans de Goede6d1bfcc2018-05-13 09:24:33 +02001464 dmi_id = dmi_first_match(byt_rt5640_quirk_table);
1465 if (dmi_id)
1466 byt_rt5640_quirk = (unsigned long)dmi_id->driver_data;
Pierre-Louis Bossart2fb2a192019-04-19 15:12:17 -05001467 if (quirk_override != -1) {
Pierre-Louis Bossart2697f3a2020-06-25 14:12:57 -05001468 dev_info(&pdev->dev, "Overriding quirk 0x%lx => 0x%x\n",
1469 byt_rt5640_quirk, quirk_override);
Takashi Iwai9f2cf732017-04-23 09:22:56 +02001470 byt_rt5640_quirk = quirk_override;
1471 }
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001472
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001473 codec_dev = bus_find_device_by_name(&i2c_bus_type, NULL, byt_rt5640_codec_name);
1474 if (!codec_dev)
1475 return -EPROBE_DEFER;
1476
1477 priv->codec_dev = codec_dev;
1478
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001479 /* Must be called before register_card, also see declaration comment. */
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001480 ret_val = byt_rt5640_add_codec_device_props(codec_dev, priv);
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001481 if (ret_val)
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001482 goto err;
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001483
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -05001484 log_quirks(&pdev->dev);
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -06001485
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001486 if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
Hans de Goede9f47c9c2021-03-07 16:05:03 +01001487 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
Nariman Etemadi29686832020-01-15 17:46:17 +01001488 byt_rt5640_dais[dai_index].codecs->dai_name = "rt5640-aif2";
Hans de Goede9f47c9c2021-03-07 16:05:03 +01001489 aif = 2;
1490 } else {
1491 aif = 1;
1492 }
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -05001493
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001494 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
Nariman Etemadi29686832020-01-15 17:46:17 +01001495 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2))
1496 byt_rt5640_dais[dai_index].cpus->dai_name = "ssp0-port";
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001497
Pierre-Louis Bossart7735bce2017-09-08 12:43:52 -05001498 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001499 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
1500 if (IS_ERR(priv->mclk)) {
Pierre-Louis Bossart4a8b3a62016-12-16 10:55:49 -06001501 ret_val = PTR_ERR(priv->mclk);
1502
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001503 dev_err(&pdev->dev,
Pierre-Louis Bossart4a8b3a62016-12-16 10:55:49 -06001504 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
1505 ret_val);
1506
1507 /*
1508 * Fall back to bit clock usage for -ENOENT (clock not
1509 * available likely due to missing dependencies), bail
1510 * for all other errors, including -EPROBE_DEFER
1511 */
1512 if (ret_val != -ENOENT)
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001513 goto err;
Pierre-Louis Bossart4a8b3a62016-12-16 10:55:49 -06001514 byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001515 }
1516 }
1517
Hans de Goede1851ccf2021-01-09 22:01:17 +01001518 if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS) {
1519 cfg_spk = 0;
1520 spk_type = "none";
1521 } else if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1522 cfg_spk = 1;
1523 spk_type = "mono";
1524 } else {
1525 cfg_spk = 2;
1526 spk_type = "stereo";
1527 }
1528
Hans de Goede044c7652021-08-02 16:24:59 +02001529 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT) {
1530 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT_AS_HP2)
1531 lineout_string = " cfg-hp2:lineout";
1532 else
1533 lineout_string = " cfg-lineout:1";
1534 }
Hans de Goededd3e2022021-08-02 16:24:57 +02001535
Hans de Goede79c1123b2021-08-02 16:25:00 +02001536 if (byt_rt5640_quirk & BYT_RT5640_HSMIC2_ON_IN1)
1537 headset2_string = " cfg-hs2:in1";
1538
Jaroslav Kysela0d5c8182019-12-04 15:15:45 -06001539 snprintf(byt_rt5640_components, sizeof(byt_rt5640_components),
Hans de Goede79c1123b2021-08-02 16:25:00 +02001540 "cfg-spk:%d cfg-mic:%s aif:%d%s%s", cfg_spk,
Hans de Goededd3e2022021-08-02 16:24:57 +02001541 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)], aif,
Hans de Goede79c1123b2021-08-02 16:25:00 +02001542 lineout_string, headset2_string);
Jaroslav Kysela0d5c8182019-12-04 15:15:45 -06001543 byt_rt5640_card.components = byt_rt5640_components;
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001544#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
Hans de Goede063422c2018-05-13 09:24:35 +02001545 snprintf(byt_rt5640_long_name, sizeof(byt_rt5640_long_name),
Hans de Goede1851ccf2021-01-09 22:01:17 +01001546 "bytcr-rt5640-%s-spk-%s-mic", spk_type,
Hans de Goede063422c2018-05-13 09:24:35 +02001547 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1548 byt_rt5640_card.long_name = byt_rt5640_long_name;
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001549#endif
Hans de Goede063422c2018-05-13 09:24:35 +02001550
Pierre-Louis Bossartbd7661b2019-01-25 14:34:59 -06001551 /* override plaform name, if required */
1552 platform_name = mach->mach_params.platform;
1553
1554 ret_val = snd_soc_fixup_dai_links_platform_name(&byt_rt5640_card,
1555 platform_name);
1556 if (ret_val)
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001557 goto err;
Pierre-Louis Bossartbd7661b2019-01-25 14:34:59 -06001558
Pierre-Louis Bossart41656c32020-11-12 16:38:16 -06001559 sof_parent = snd_soc_acpi_sof_parent(&pdev->dev);
1560
1561 /* set card and driver name */
1562 if (sof_parent) {
1563 byt_rt5640_card.name = SOF_CARD_NAME;
1564 byt_rt5640_card.driver_name = SOF_DRIVER_NAME;
1565 } else {
1566 byt_rt5640_card.name = CARD_NAME;
1567 byt_rt5640_card.driver_name = DRIVER_NAME;
1568 }
1569
Pierre-Louis Bossart05ff3122020-11-12 16:38:17 -06001570 /* set pm ops */
1571 if (sof_parent)
1572 dev->driver->pm = &snd_soc_pm_ops;
1573
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001574 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
1575
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301576 if (ret_val) {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001577 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
1578 ret_val);
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001579 goto err;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301580 }
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001581 platform_set_drvdata(pdev, &byt_rt5640_card);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301582 return ret_val;
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001583
1584err:
1585 put_device(priv->codec_dev);
1586 return ret_val;
1587}
1588
1589static int snd_byt_rt5640_mc_remove(struct platform_device *pdev)
1590{
1591 struct snd_soc_card *card = platform_get_drvdata(pdev);
1592 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1593
1594 put_device(priv->codec_dev);
1595 return 0;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301596}
1597
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001598static struct platform_driver snd_byt_rt5640_mc_driver = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301599 .driver = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001600 .name = "bytcr_rt5640",
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301601 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001602 .probe = snd_byt_rt5640_mc_probe,
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001603 .remove = snd_byt_rt5640_mc_remove,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301604};
1605
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001606module_platform_driver(snd_byt_rt5640_mc_driver);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301607
1608MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
1609MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
1610MODULE_LICENSE("GPL v2");
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001611MODULE_ALIAS("platform:bytcr_rt5640");