blob: a0c5f0e9c22a1734b46a79b57ba2509b13fdbbb4 [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 Goede9ba00852021-08-19 21:05:43 +020021#include <linux/gpio/consumer.h>
22#include <linux/gpio/machine.h>
Hans de Goede77323102018-05-13 09:24:28 +020023#include <linux/input.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053024#include <linux/slab.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053025#include <sound/pcm.h>
26#include <sound/pcm_params.h>
27#include <sound/soc.h>
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060028#include <sound/jack.h>
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050029#include <sound/soc-acpi.h>
Hans de Goedea3ad2912018-05-13 09:24:26 +020030#include <dt-bindings/sound/rt5640.h>
Jie Yange56c72d2015-04-02 15:37:02 +080031#include "../../codecs/rt5640.h"
Jie Yangb97169d2015-04-02 15:37:04 +080032#include "../atom/sst-atom-controls.h"
Pierre-Louis Bossart536cfd22019-05-30 06:50:11 -050033#include "../common/soc-intel-quirks.h"
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053034
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060035enum {
36 BYT_RT5640_DMIC1_MAP,
37 BYT_RT5640_DMIC2_MAP,
38 BYT_RT5640_IN1_MAP,
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -050039 BYT_RT5640_IN3_MAP,
Hans de Goede46466ab2021-01-09 22:01:18 +010040 BYT_RT5640_NO_INTERNAL_MIC_MAP,
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060041};
42
Hans de Goede77323102018-05-13 09:24:28 +020043enum {
44 BYT_RT5640_JD_SRC_GPIO1 = (RT5640_JD_SRC_GPIO1 << 4),
45 BYT_RT5640_JD_SRC_JD1_IN4P = (RT5640_JD_SRC_JD1_IN4P << 4),
46 BYT_RT5640_JD_SRC_JD2_IN4N = (RT5640_JD_SRC_JD2_IN4N << 4),
47 BYT_RT5640_JD_SRC_GPIO2 = (RT5640_JD_SRC_GPIO2 << 4),
48 BYT_RT5640_JD_SRC_GPIO3 = (RT5640_JD_SRC_GPIO3 << 4),
49 BYT_RT5640_JD_SRC_GPIO4 = (RT5640_JD_SRC_GPIO4 << 4),
50};
Irina Tirdeadf1a2772016-08-12 16:27:57 -050051
Hans de Goede77323102018-05-13 09:24:28 +020052enum {
53 BYT_RT5640_OVCD_TH_600UA = (6 << 8),
54 BYT_RT5640_OVCD_TH_1500UA = (15 << 8),
55 BYT_RT5640_OVCD_TH_2000UA = (20 << 8),
56};
57
58enum {
59 BYT_RT5640_OVCD_SF_0P5 = (RT5640_OVCD_SF_0P5 << 13),
60 BYT_RT5640_OVCD_SF_0P75 = (RT5640_OVCD_SF_0P75 << 13),
61 BYT_RT5640_OVCD_SF_1P0 = (RT5640_OVCD_SF_1P0 << 13),
62 BYT_RT5640_OVCD_SF_1P5 = (RT5640_OVCD_SF_1P5 << 13),
63};
64
65#define BYT_RT5640_MAP(quirk) ((quirk) & GENMASK(3, 0))
66#define BYT_RT5640_JDSRC(quirk) (((quirk) & GENMASK(7, 4)) >> 4)
67#define BYT_RT5640_OVCD_TH(quirk) (((quirk) & GENMASK(12, 8)) >> 8)
68#define BYT_RT5640_OVCD_SF(quirk) (((quirk) & GENMASK(14, 13)) >> 13)
69#define BYT_RT5640_JD_NOT_INV BIT(16)
70#define BYT_RT5640_MONO_SPEAKER BIT(17)
71#define BYT_RT5640_DIFF_MIC BIT(18) /* default is single-ended */
72#define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */
73#define BYT_RT5640_SSP0_AIF1 BIT(20)
74#define BYT_RT5640_SSP0_AIF2 BIT(21)
75#define BYT_RT5640_MCLK_EN BIT(22)
76#define BYT_RT5640_MCLK_25MHZ BIT(23)
Hans de Goede1851ccf2021-01-09 22:01:17 +010077#define BYT_RT5640_NO_SPEAKERS BIT(24)
Hans de Goededd3e2022021-08-02 16:24:57 +020078#define BYT_RT5640_LINEOUT BIT(25)
Hans de Goede044c7652021-08-02 16:24:59 +020079#define BYT_RT5640_LINEOUT_AS_HP2 BIT(26)
Hans de Goede79c1123b2021-08-02 16:25:00 +020080#define BYT_RT5640_HSMIC2_ON_IN1 BIT(27)
Hans de Goede9ba00852021-08-19 21:05:43 +020081#define BYT_RT5640_JD_HP_ELITEP_1000G2 BIT(28)
Hans de Goede77323102018-05-13 09:24:28 +020082
Hans de Goede96a388fe2018-05-13 09:24:30 +020083#define BYTCR_INPUT_DEFAULTS \
84 (BYT_RT5640_IN3_MAP | \
Hans de Goede56ff4402018-05-13 09:24:31 +020085 BYT_RT5640_JD_SRC_JD1_IN4P | \
86 BYT_RT5640_OVCD_TH_2000UA | \
87 BYT_RT5640_OVCD_SF_0P75 | \
Hans de Goede96a388fe2018-05-13 09:24:30 +020088 BYT_RT5640_DIFF_MIC)
89
Hans de Goede77323102018-05-13 09:24:28 +020090/* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
91#define MAX_NO_PROPS 6
Hans de Goede6a7c05e2018-05-08 17:35:54 +020092
Irina Tirdeadf1a2772016-08-12 16:27:57 -050093struct byt_rt5640_private {
Hans de Goede77323102018-05-13 09:24:28 +020094 struct snd_soc_jack jack;
Hans de Goede9ba00852021-08-19 21:05:43 +020095 struct snd_soc_jack jack2;
96 struct gpio_desc *hsmic_detect;
Irina Tirdeadf1a2772016-08-12 16:27:57 -050097 struct clk *mclk;
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -050098 struct device *codec_dev;
Irina Tirdeadf1a2772016-08-12 16:27:57 -050099};
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500100static bool is_bytcr;
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -0600101
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -0600102static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN;
Pierre-Louis Bossart2fb2a192019-04-19 15:12:17 -0500103static int quirk_override = -1;
104module_param_named(quirk, quirk_override, int, 0444);
Takashi Iwai9f2cf732017-04-23 09:22:56 +0200105MODULE_PARM_DESC(quirk, "Board-specific quirk override");
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500106
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500107static void log_quirks(struct device *dev)
108{
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500109 int map;
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500110 bool has_mclk = false;
111 bool has_ssp0 = false;
112 bool has_ssp0_aif1 = false;
113 bool has_ssp0_aif2 = false;
114 bool has_ssp2_aif2 = false;
115
116 map = BYT_RT5640_MAP(byt_rt5640_quirk);
117 switch (map) {
118 case BYT_RT5640_DMIC1_MAP:
119 dev_info(dev, "quirk DMIC1_MAP enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500120 break;
121 case BYT_RT5640_DMIC2_MAP:
122 dev_info(dev, "quirk DMIC2_MAP enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500123 break;
124 case BYT_RT5640_IN1_MAP:
125 dev_info(dev, "quirk IN1_MAP enabled\n");
126 break;
127 case BYT_RT5640_IN3_MAP:
128 dev_info(dev, "quirk IN3_MAP enabled\n");
129 break;
Hans de Goede46466ab2021-01-09 22:01:18 +0100130 case BYT_RT5640_NO_INTERNAL_MIC_MAP:
131 dev_info(dev, "quirk NO_INTERNAL_MIC_MAP enabled\n");
132 break;
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500133 default:
134 dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
135 break;
136 }
Hans de Goede79c1123b2021-08-02 16:25:00 +0200137 if (byt_rt5640_quirk & BYT_RT5640_HSMIC2_ON_IN1)
138 dev_info(dev, "quirk HSMIC2_ON_IN1 enabled\n");
Hans de Goede77323102018-05-13 09:24:28 +0200139 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
140 dev_info(dev, "quirk realtek,jack-detect-source %ld\n",
141 BYT_RT5640_JDSRC(byt_rt5640_quirk));
142 dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n",
143 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
144 dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n",
145 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
146 }
147 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
148 dev_info(dev, "quirk JD_NOT_INV enabled\n");
Hans de Goede9ba00852021-08-19 21:05:43 +0200149 if (byt_rt5640_quirk & BYT_RT5640_JD_HP_ELITEP_1000G2)
150 dev_info(dev, "quirk JD_HP_ELITEPAD_1000G2 enabled\n");
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500151 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500152 dev_info(dev, "quirk MONO_SPEAKER enabled\n");
Hans de Goede1851ccf2021-01-09 22:01:17 +0100153 if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)
154 dev_info(dev, "quirk NO_SPEAKERS enabled\n");
Hans de Goededd3e2022021-08-02 16:24:57 +0200155 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT)
156 dev_info(dev, "quirk LINEOUT enabled\n");
Hans de Goede044c7652021-08-02 16:24:59 +0200157 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT_AS_HP2)
158 dev_info(dev, "quirk LINEOUT_AS_HP2 enabled\n");
Hans de Goedea3ad2912018-05-13 09:24:26 +0200159 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
160 dev_info(dev, "quirk DIFF_MIC enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500161 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
162 dev_info(dev, "quirk SSP0_AIF1 enabled\n");
163 has_ssp0 = true;
164 has_ssp0_aif1 = true;
165 }
166 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
167 dev_info(dev, "quirk SSP0_AIF2 enabled\n");
168 has_ssp0 = true;
169 has_ssp0_aif2 = true;
170 }
171 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
172 dev_info(dev, "quirk SSP2_AIF2 enabled\n");
173 has_ssp2_aif2 = true;
174 }
175 if (is_bytcr && !has_ssp0)
176 dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2 on bytcr\n");
177 if (has_ssp0_aif1 && has_ssp0_aif2)
178 dev_err(dev, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n");
179 if (has_ssp0 && has_ssp2_aif2)
180 dev_err(dev, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n");
181
182 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
183 dev_info(dev, "quirk MCLK_EN enabled\n");
184 has_mclk = true;
185 }
186 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
187 if (has_mclk)
188 dev_info(dev, "quirk MCLK_25MHZ enabled\n");
189 else
190 dev_err(dev, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n");
191 }
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500192}
193
Hans de Goedebcd9a322018-05-08 17:35:53 +0200194static int byt_rt5640_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai,
195 int rate)
196{
197 int ret;
198
199 /* Configure the PLL before selecting it */
200 if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) {
201 /* use bitclock as PLL input */
202 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
203 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
204 /* 2x16 bit slots on SSP0 */
205 ret = snd_soc_dai_set_pll(codec_dai, 0,
206 RT5640_PLL1_S_BCLK1,
207 rate * 32, rate * 512);
208 } else {
209 /* 2x15 bit slots on SSP2 */
210 ret = snd_soc_dai_set_pll(codec_dai, 0,
211 RT5640_PLL1_S_BCLK1,
212 rate * 50, rate * 512);
213 }
214 } else {
215 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
216 ret = snd_soc_dai_set_pll(codec_dai, 0,
217 RT5640_PLL1_S_MCLK,
218 25000000, rate * 512);
219 } else {
220 ret = snd_soc_dai_set_pll(codec_dai, 0,
221 RT5640_PLL1_S_MCLK,
222 19200000, rate * 512);
223 }
224 }
225
226 if (ret < 0) {
Hans de Goedea3a956a2018-05-11 11:52:16 +0200227 dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret);
Hans de Goedebcd9a322018-05-08 17:35:53 +0200228 return ret;
229 }
230
231 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
232 rate * 512, SND_SOC_CLOCK_IN);
233 if (ret < 0) {
Hans de Goedea3a956a2018-05-11 11:52:16 +0200234 dev_err(codec_dai->component->dev, "can't set clock %d\n", ret);
Hans de Goedebcd9a322018-05-08 17:35:53 +0200235 return ret;
236 }
237
238 return 0;
239}
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500240
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500241#define BYT_CODEC_DAI1 "rt5640-aif1"
242#define BYT_CODEC_DAI2 "rt5640-aif2"
243
Hans de Goede81071142021-08-02 16:24:58 +0200244static struct snd_soc_dai *byt_rt5640_get_codec_dai(struct snd_soc_dapm_context *dapm)
245{
246 struct snd_soc_card *card = dapm->card;
247 struct snd_soc_dai *codec_dai;
248
249 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1);
250 if (!codec_dai)
251 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2);
252 if (!codec_dai)
253 dev_err(card->dev, "Error codec dai not found\n");
254
255 return codec_dai;
256}
257
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500258static int platform_clock_control(struct snd_soc_dapm_widget *w,
259 struct snd_kcontrol *k, int event)
260{
261 struct snd_soc_dapm_context *dapm = w->dapm;
262 struct snd_soc_card *card = dapm->card;
263 struct snd_soc_dai *codec_dai;
264 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
265 int ret;
266
Hans de Goede81071142021-08-02 16:24:58 +0200267 codec_dai = byt_rt5640_get_codec_dai(dapm);
Pierre-Louis Bossartdfb6ec72017-10-12 18:38:03 -0500268 if (!codec_dai)
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500269 return -EIO;
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500270
271 if (SND_SOC_DAPM_EVENT_ON(event)) {
Andy Shevchenkoa15ca6e2021-10-07 19:57:14 +0300272 ret = clk_prepare_enable(priv->mclk);
273 if (ret < 0) {
274 dev_err(card->dev, "could not configure MCLK state\n");
275 return ret;
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500276 }
Hans de Goedebcd9a322018-05-08 17:35:53 +0200277 ret = byt_rt5640_prepare_and_enable_pll1(codec_dai, 48000);
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500278 } else {
279 /*
280 * Set codec clock source to internal clock before
281 * turning off the platform clock. Codec needs clock
282 * for Jack detection and button press
283 */
284 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK,
Pierre-Louis Bossart60448b02017-01-04 15:44:52 -0600285 48000 * 512,
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500286 SND_SOC_CLOCK_IN);
Andy Shevchenkoa15ca6e2021-10-07 19:57:14 +0300287 if (!ret)
288 clk_disable_unprepare(priv->mclk);
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500289 }
290
291 if (ret < 0) {
292 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
293 return ret;
294 }
295
296 return 0;
297}
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -0600298
Hans de Goede044c7652021-08-02 16:24:59 +0200299static int byt_rt5640_event_lineout(struct snd_soc_dapm_widget *w,
300 struct snd_kcontrol *k, int event)
301{
302 unsigned int gpio_ctrl3_val = RT5640_GP1_PF_OUT;
303 struct snd_soc_dai *codec_dai;
304
305 if (!(byt_rt5640_quirk & BYT_RT5640_LINEOUT_AS_HP2))
306 return 0;
307
308 /*
309 * On devices which use line-out as a second headphones output,
310 * the codec's GPIO1 pin is used to enable an external HP-amp.
311 */
312
313 codec_dai = byt_rt5640_get_codec_dai(w->dapm);
314 if (!codec_dai)
315 return -EIO;
316
317 if (SND_SOC_DAPM_EVENT_ON(event))
318 gpio_ctrl3_val |= RT5640_GP1_OUT_HI;
319
320 snd_soc_component_update_bits(codec_dai->component, RT5640_GPIO_CTRL3,
321 RT5640_GP1_PF_MASK | RT5640_GP1_OUT_MASK, gpio_ctrl3_val);
322
323 return 0;
324}
325
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600326static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530327 SND_SOC_DAPM_HP("Headphone", NULL),
328 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Hans de Goede0a61bcb2021-08-19 21:05:42 +0200329 SND_SOC_DAPM_MIC("Headset Mic 2", NULL),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600330 SND_SOC_DAPM_MIC("Internal Mic", NULL),
331 SND_SOC_DAPM_SPK("Speaker", NULL),
Hans de Goede044c7652021-08-02 16:24:59 +0200332 SND_SOC_DAPM_LINE("Line Out", byt_rt5640_event_lineout),
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500333 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
334 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
335 SND_SOC_DAPM_POST_PMD),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530336};
337
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600338static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500339 {"Headphone", NULL, "Platform Clock"},
340 {"Headset Mic", NULL, "Platform Clock"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530341 {"Headset Mic", NULL, "MICBIAS1"},
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600342 {"IN2P", NULL, "Headset Mic"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530343 {"Headphone", NULL, "HPOL"},
344 {"Headphone", NULL, "HPOR"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530345};
346
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600347static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
Hans de Goededccd1df2021-08-02 16:24:56 +0200348 {"Internal Mic", NULL, "Platform Clock"},
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600349 {"DMIC1", NULL, "Internal Mic"},
350};
351
352static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
Hans de Goededccd1df2021-08-02 16:24:56 +0200353 {"Internal Mic", NULL, "Platform Clock"},
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600354 {"DMIC2", NULL, "Internal Mic"},
355};
356
357static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
Hans de Goededccd1df2021-08-02 16:24:56 +0200358 {"Internal Mic", NULL, "Platform Clock"},
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600359 {"Internal Mic", NULL, "MICBIAS1"},
360 {"IN1P", NULL, "Internal Mic"},
361};
362
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -0500363static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
Hans de Goededccd1df2021-08-02 16:24:56 +0200364 {"Internal Mic", NULL, "Platform Clock"},
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -0500365 {"Internal Mic", NULL, "MICBIAS1"},
366 {"IN3P", NULL, "Internal Mic"},
367};
368
Hans de Goede0a61bcb2021-08-19 21:05:42 +0200369static const struct snd_soc_dapm_route byt_rt5640_hsmic2_in1_map[] = {
370 {"Headset Mic 2", NULL, "Platform Clock"},
371 {"Headset Mic 2", NULL, "MICBIAS1"},
372 {"IN1P", NULL, "Headset Mic 2"},
373};
374
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500375static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
376 {"ssp2 Tx", NULL, "codec_out0"},
377 {"ssp2 Tx", NULL, "codec_out1"},
378 {"codec_in0", NULL, "ssp2 Rx"},
379 {"codec_in1", NULL, "ssp2 Rx"},
380
381 {"AIF1 Playback", NULL, "ssp2 Tx"},
382 {"ssp2 Rx", NULL, "AIF1 Capture"},
383};
384
385static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
386 {"ssp2 Tx", NULL, "codec_out0"},
387 {"ssp2 Tx", NULL, "codec_out1"},
388 {"codec_in0", NULL, "ssp2 Rx"},
389 {"codec_in1", NULL, "ssp2 Rx"},
390
391 {"AIF2 Playback", NULL, "ssp2 Tx"},
392 {"ssp2 Rx", NULL, "AIF2 Capture"},
393};
394
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500395static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
396 {"ssp0 Tx", NULL, "modem_out"},
397 {"modem_in", NULL, "ssp0 Rx"},
398
399 {"AIF1 Playback", NULL, "ssp0 Tx"},
400 {"ssp0 Rx", NULL, "AIF1 Capture"},
401};
402
403static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
404 {"ssp0 Tx", NULL, "modem_out"},
405 {"modem_in", NULL, "ssp0 Rx"},
406
407 {"AIF2 Playback", NULL, "ssp0 Tx"},
408 {"ssp0 Rx", NULL, "AIF2 Capture"},
409};
410
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500411static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
Hans de Goededccd1df2021-08-02 16:24:56 +0200412 {"Speaker", NULL, "Platform Clock"},
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500413 {"Speaker", NULL, "SPOLP"},
414 {"Speaker", NULL, "SPOLN"},
415 {"Speaker", NULL, "SPORP"},
416 {"Speaker", NULL, "SPORN"},
417};
418
419static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
Hans de Goededccd1df2021-08-02 16:24:56 +0200420 {"Speaker", NULL, "Platform Clock"},
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500421 {"Speaker", NULL, "SPOLP"},
422 {"Speaker", NULL, "SPOLN"},
423};
424
Hans de Goededd3e2022021-08-02 16:24:57 +0200425static const struct snd_soc_dapm_route byt_rt5640_lineout_map[] = {
426 {"Line Out", NULL, "Platform Clock"},
427 {"Line Out", NULL, "LOUTR"},
428 {"Line Out", NULL, "LOUTL"},
429};
430
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600431static const struct snd_kcontrol_new byt_rt5640_controls[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530432 SOC_DAPM_PIN_SWITCH("Headphone"),
433 SOC_DAPM_PIN_SWITCH("Headset Mic"),
Hans de Goede0a61bcb2021-08-19 21:05:42 +0200434 SOC_DAPM_PIN_SWITCH("Headset Mic 2"),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600435 SOC_DAPM_PIN_SWITCH("Internal Mic"),
436 SOC_DAPM_PIN_SWITCH("Speaker"),
Hans de Goededd3e2022021-08-02 16:24:57 +0200437 SOC_DAPM_PIN_SWITCH("Line Out"),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530438};
439
Hans de Goede77323102018-05-13 09:24:28 +0200440static struct snd_soc_jack_pin rt5640_pins[] = {
441 {
442 .pin = "Headphone",
443 .mask = SND_JACK_HEADPHONE,
444 },
445 {
446 .pin = "Headset Mic",
447 .mask = SND_JACK_MICROPHONE,
448 },
449};
450
Hans de Goede9ba00852021-08-19 21:05:43 +0200451static struct snd_soc_jack_pin rt5640_pins2[] = {
452 {
453 /* The 2nd headset jack uses lineout with an external HP-amp */
454 .pin = "Line Out",
455 .mask = SND_JACK_HEADPHONE,
456 },
457 {
458 .pin = "Headset Mic 2",
459 .mask = SND_JACK_MICROPHONE,
460 },
461};
462
Peter Ujfalusidc2d01c2021-08-25 15:25:19 +0300463static struct snd_soc_jack_gpio rt5640_jack_gpio = {
Hans de Goede9ba00852021-08-19 21:05:43 +0200464 .name = "hp-detect",
465 .report = SND_JACK_HEADSET,
466 .invert = true,
467 .debounce_time = 200,
468};
469
Peter Ujfalusidc2d01c2021-08-25 15:25:19 +0300470static struct snd_soc_jack_gpio rt5640_jack2_gpio = {
Hans de Goede9ba00852021-08-19 21:05:43 +0200471 .name = "hp2-detect",
472 .report = SND_JACK_HEADSET,
473 .invert = true,
474 .debounce_time = 200,
475};
476
477static const struct acpi_gpio_params acpi_gpio0 = { 0, 0, false };
478static const struct acpi_gpio_params acpi_gpio1 = { 1, 0, false };
479static const struct acpi_gpio_params acpi_gpio2 = { 2, 0, false };
480
481static const struct acpi_gpio_mapping byt_rt5640_hp_elitepad_1000g2_gpios[] = {
482 { "hp-detect-gpios", &acpi_gpio0, 1, },
483 { "headset-mic-detect-gpios", &acpi_gpio1, 1, },
484 { "hp2-detect-gpios", &acpi_gpio2, 1, },
485 { },
486};
487
Hans de Goedea5ec3772021-08-23 13:04:32 +0200488static int byt_rt5640_hp_elitepad_1000g2_jack1_check(void *data)
Hans de Goede9ba00852021-08-19 21:05:43 +0200489{
490 struct byt_rt5640_private *priv = data;
491 int jack_status, mic_status;
492
493 jack_status = gpiod_get_value_cansleep(rt5640_jack_gpio.desc);
494 if (jack_status)
495 return 0;
496
497 mic_status = gpiod_get_value_cansleep(priv->hsmic_detect);
498 if (mic_status)
499 return SND_JACK_HEADPHONE;
500 else
501 return SND_JACK_HEADSET;
502}
503
Hans de Goedea5ec3772021-08-23 13:04:32 +0200504static int byt_rt5640_hp_elitepad_1000g2_jack2_check(void *data)
Hans de Goede9ba00852021-08-19 21:05:43 +0200505{
506 struct snd_soc_component *component = data;
507 int jack_status, report;
508
509 jack_status = gpiod_get_value_cansleep(rt5640_jack2_gpio.desc);
510 if (jack_status)
511 return 0;
512
513 rt5640_enable_micbias1_for_ovcd(component);
514 report = rt5640_detect_headset(component, rt5640_jack2_gpio.desc);
515 rt5640_disable_micbias1_for_ovcd(component);
516
517 return report;
518}
519
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600520static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530521 struct snd_pcm_hw_params *params)
522{
Kuninori Morimoto2207b932020-07-27 10:08:29 +0900523 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +0900524 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530525
Hans de Goedebcd9a322018-05-08 17:35:53 +0200526 return byt_rt5640_prepare_and_enable_pll1(dai, params_rate(params));
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530527}
528
Hans de Goede3c0d0112018-05-13 09:24:32 +0200529/* Please keep this list alphabetically sorted */
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600530static const struct dmi_system_id byt_rt5640_quirk_table[] = {
Hans de Goedeec8e8412018-05-13 09:24:34 +0200531 { /* Acer Iconia Tab 8 W1-810 */
532 .matches = {
533 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
534 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
535 },
536 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
537 BYT_RT5640_JD_SRC_JD1_IN4P |
Hans de Goedef12a0a32018-06-03 15:42:32 +0200538 BYT_RT5640_OVCD_TH_1500UA |
Hans de Goedeec8e8412018-05-13 09:24:34 +0200539 BYT_RT5640_OVCD_SF_0P75 |
540 BYT_RT5640_SSP0_AIF1 |
541 BYT_RT5640_MCLK_EN),
542 },
Hans de Goedec58947a2021-02-16 22:35:55 +0100543 { /* Acer One 10 S1002 */
544 .matches = {
545 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
546 DMI_MATCH(DMI_PRODUCT_NAME, "One S1002"),
547 },
548 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
549 BYT_RT5640_JD_SRC_JD2_IN4N |
550 BYT_RT5640_OVCD_TH_2000UA |
551 BYT_RT5640_OVCD_SF_0P75 |
552 BYT_RT5640_DIFF_MIC |
553 BYT_RT5640_SSP0_AIF2 |
554 BYT_RT5640_MCLK_EN),
555 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600556 {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600557 .matches = {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200558 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
559 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
560 },
Hans de Goede0bb88772019-11-19 15:51:38 +0100561 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
562 BYT_RT5640_JD_SRC_JD2_IN4N |
563 BYT_RT5640_OVCD_TH_2000UA |
564 BYT_RT5640_OVCD_SF_0P75 |
565 BYT_RT5640_SSP0_AIF1 |
566 BYT_RT5640_MCLK_EN),
Hans de Goede3c0d0112018-05-13 09:24:32 +0200567 },
568 {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200569 .matches = {
Hans de Goedebcf441a2018-05-28 22:26:49 +0200570 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
571 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 80 Cesium"),
572 },
573 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
574 BYT_RT5640_MONO_SPEAKER |
575 BYT_RT5640_SSP0_AIF1 |
576 BYT_RT5640_MCLK_EN),
577 },
578 {
579 .matches = {
Chris Chiu1bea2252020-12-08 14:04:14 +0800580 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
581 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 140 CESIUM"),
582 },
583 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
584 BYT_RT5640_JD_SRC_JD2_IN4N |
585 BYT_RT5640_OVCD_TH_2000UA |
586 BYT_RT5640_OVCD_SF_0P75 |
587 BYT_RT5640_SSP0_AIF1 |
588 BYT_RT5640_MCLK_EN),
589 },
590 {
591 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500592 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
Stephan Gerhold51a13e42019-01-02 20:39:08 +0100593 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
594 },
595 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
596 BYT_RT5640_JD_SRC_JD2_IN4N |
597 BYT_RT5640_OVCD_TH_2000UA |
598 BYT_RT5640_OVCD_SF_0P75 |
599 BYT_RT5640_SSP0_AIF1 |
600 BYT_RT5640_MCLK_EN),
601 },
602 {
603 .matches = {
604 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500605 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600606 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500607 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
Hans de Goede77323102018-05-13 09:24:28 +0200608 BYT_RT5640_JD_SRC_JD2_IN4N |
609 BYT_RT5640_OVCD_TH_2000UA |
610 BYT_RT5640_OVCD_SF_0P75 |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500611 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600612 },
613 {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600614 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500615 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
616 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
617 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500618 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
Hans de Goedeb7c72032021-03-12 12:48:50 +0100619 BYT_RT5640_JD_SRC_JD2_IN4N |
620 BYT_RT5640_OVCD_TH_2000UA |
621 BYT_RT5640_OVCD_SF_0P75 |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500622 BYT_RT5640_MONO_SPEAKER |
623 BYT_RT5640_DIFF_MIC |
624 BYT_RT5640_SSP0_AIF2 |
625 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500626 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200627 { /* Chuwi Vi8 (CWI506) */
628 .matches = {
629 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"),
630 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "i86"),
631 /* The above are too generic, also match BIOS info */
632 DMI_MATCH(DMI_BIOS_VERSION, "CHUWI.D86JLBNR"),
633 },
634 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
635 BYT_RT5640_MONO_SPEAKER |
636 BYT_RT5640_SSP0_AIF1 |
637 BYT_RT5640_MCLK_EN),
638 },
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500639 {
Hans de Goeded5a18262018-06-08 10:19:25 +0200640 /* Chuwi Vi10 (CWI505) */
641 .matches = {
642 DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
643 DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"),
644 DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
645 DMI_MATCH(DMI_PRODUCT_NAME, "S165"),
646 },
647 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
648 BYT_RT5640_JD_SRC_JD2_IN4N |
649 BYT_RT5640_OVCD_TH_2000UA |
650 BYT_RT5640_OVCD_SF_0P75 |
651 BYT_RT5640_DIFF_MIC |
652 BYT_RT5640_SSP0_AIF1 |
653 BYT_RT5640_MCLK_EN),
654 },
655 {
Hans de Goede875c40e2021-03-25 23:10:54 +0100656 /* Chuwi Hi8 (CWI509) */
657 .matches = {
658 DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
659 DMI_MATCH(DMI_BOARD_NAME, "BYT-PA03C"),
660 DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
661 DMI_MATCH(DMI_PRODUCT_NAME, "S806"),
662 },
663 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
664 BYT_RT5640_JD_SRC_JD2_IN4N |
665 BYT_RT5640_OVCD_TH_2000UA |
666 BYT_RT5640_OVCD_SF_0P75 |
667 BYT_RT5640_MONO_SPEAKER |
668 BYT_RT5640_DIFF_MIC |
669 BYT_RT5640_SSP0_AIF1 |
670 BYT_RT5640_MCLK_EN),
671 },
672 {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500673 .matches = {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200674 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
675 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
676 },
677 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP),
678 },
Hans de Goede9ee6f8a2018-07-01 11:30:23 +0200679 { /* Connect Tablet 9 */
680 .matches = {
681 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Connect"),
682 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Tablet 9"),
683 },
684 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
685 BYT_RT5640_MONO_SPEAKER |
686 BYT_RT5640_SSP0_AIF1 |
687 BYT_RT5640_MCLK_EN),
688 },
Hans de Goede3c0d0112018-05-13 09:24:32 +0200689 {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200690 .matches = {
Hans de Goede6748fb72018-05-13 09:24:27 +0200691 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500692 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600693 },
Hans de Goede6748fb72018-05-13 09:24:27 +0200694 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
Hans de Goede77323102018-05-13 09:24:28 +0200695 BYT_RT5640_JD_SRC_JD2_IN4N |
696 BYT_RT5640_OVCD_TH_2000UA |
697 BYT_RT5640_OVCD_SF_0P75 |
Hans de Goede6748fb72018-05-13 09:24:27 +0200698 BYT_RT5640_MONO_SPEAKER |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500699 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600700 },
Hans de Goedebdea43f2021-02-16 22:35:52 +0100701 { /* Estar Beauty HD MID 7316R */
702 .matches = {
703 DMI_MATCH(DMI_SYS_VENDOR, "Estar"),
704 DMI_MATCH(DMI_PRODUCT_NAME, "eSTAR BEAUTY HD Intel Quad core"),
705 },
706 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
707 BYT_RT5640_MONO_SPEAKER |
708 BYT_RT5640_SSP0_AIF1 |
709 BYT_RT5640_MCLK_EN),
710 },
Hans de Goede28c268d2021-05-08 17:01:45 +0200711 { /* Glavey TM800A550L */
712 .matches = {
713 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
714 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
715 /* Above strings are too generic, also match on BIOS version */
716 DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
717 },
718 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
719 BYT_RT5640_SSP0_AIF1 |
720 BYT_RT5640_MCLK_EN),
721 },
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600722 {
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600723 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500724 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
725 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600726 },
Hans de Goede780feaf2021-08-02 16:25:01 +0200727 .driver_data = (void *)(BYT_RT5640_DMIC2_MAP |
728 BYT_RT5640_MCLK_EN |
729 BYT_RT5640_LINEOUT |
730 BYT_RT5640_LINEOUT_AS_HP2 |
Hans de Goede9ba00852021-08-19 21:05:43 +0200731 BYT_RT5640_HSMIC2_ON_IN1 |
732 BYT_RT5640_JD_HP_ELITEP_1000G2),
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600733 },
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100734 { /* HP Pavilion x2 10-k0XX, 10-n0XX */
Hans de Goedeec8e8412018-05-13 09:24:34 +0200735 .matches = {
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100736 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
737 DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion x2 Detachable"),
Hans de Goedeec8e8412018-05-13 09:24:34 +0200738 },
739 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
740 BYT_RT5640_JD_SRC_JD2_IN4N |
741 BYT_RT5640_OVCD_TH_1500UA |
742 BYT_RT5640_OVCD_SF_0P75 |
743 BYT_RT5640_SSP0_AIF1 |
744 BYT_RT5640_MCLK_EN),
745 },
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100746 { /* HP Pavilion x2 10-p0XX */
747 .matches = {
748 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
749 DMI_MATCH(DMI_PRODUCT_NAME, "HP x2 Detachable 10-p0XX"),
750 },
751 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
752 BYT_RT5640_JD_SRC_JD1_IN4P |
Hans de Goedeca08ddf2021-02-24 11:50:52 +0100753 BYT_RT5640_OVCD_TH_2000UA |
Hans de Goedefbdae7d2020-11-18 13:15:15 +0100754 BYT_RT5640_OVCD_SF_0P75 |
755 BYT_RT5640_MCLK_EN),
756 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200757 { /* HP Stream 7 */
758 .matches = {
759 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
760 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Stream 7 Tablet"),
761 },
762 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
763 BYT_RT5640_MONO_SPEAKER |
764 BYT_RT5640_JD_NOT_INV |
765 BYT_RT5640_SSP0_AIF1 |
766 BYT_RT5640_MCLK_EN),
767 },
768 { /* I.T.Works TW891 */
769 .matches = {
770 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
771 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
772 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
773 DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
774 },
775 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
776 BYT_RT5640_MONO_SPEAKER |
777 BYT_RT5640_SSP0_AIF1 |
778 BYT_RT5640_MCLK_EN),
779 },
780 { /* Lamina I8270 / T701BR.SE */
781 .matches = {
782 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Lamina"),
783 DMI_EXACT_MATCH(DMI_BOARD_NAME, "T701BR.SE"),
784 },
785 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
786 BYT_RT5640_MONO_SPEAKER |
787 BYT_RT5640_JD_NOT_INV |
788 BYT_RT5640_SSP0_AIF1 |
789 BYT_RT5640_MCLK_EN),
790 },
Hans de Goede81583af2018-07-07 12:22:10 +0200791 { /* Lenovo Miix 2 8 */
792 .matches = {
793 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
794 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "20326"),
795 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Hiking"),
796 },
797 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
798 BYT_RT5640_JD_SRC_JD2_IN4N |
799 BYT_RT5640_OVCD_TH_2000UA |
800 BYT_RT5640_OVCD_SF_0P75 |
801 BYT_RT5640_MONO_SPEAKER |
802 BYT_RT5640_MCLK_EN),
803 },
Hans de Goedef0353e12021-05-08 17:01:46 +0200804 { /* Lenovo Miix 3-830 */
805 .matches = {
806 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
807 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 3-830"),
808 },
809 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
810 BYT_RT5640_JD_SRC_JD2_IN4N |
811 BYT_RT5640_OVCD_TH_2000UA |
812 BYT_RT5640_OVCD_SF_0P75 |
813 BYT_RT5640_MONO_SPEAKER |
814 BYT_RT5640_DIFF_MIC |
815 BYT_RT5640_SSP0_AIF1 |
816 BYT_RT5640_MCLK_EN),
817 },
Hans de Goede260c48b2018-08-12 13:42:06 +0200818 { /* Linx Linx7 tablet */
819 .matches = {
820 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LINX"),
821 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LINX7"),
822 },
823 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
824 BYT_RT5640_MONO_SPEAKER |
825 BYT_RT5640_JD_NOT_INV |
826 BYT_RT5640_SSP0_AIF1 |
827 BYT_RT5640_MCLK_EN),
828 },
Hans de Goededf330322021-01-09 22:01:19 +0100829 { /* Mele PCG03 Mini PC */
830 .matches = {
831 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Mini PC"),
832 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Mini PC"),
833 },
834 .driver_data = (void *)(BYT_RT5640_NO_INTERNAL_MIC_MAP |
835 BYT_RT5640_NO_SPEAKERS |
836 BYT_RT5640_SSP0_AIF1),
837 },
Hans de Goede6a013712020-09-01 10:06:23 +0200838 { /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */
839 .matches = {
840 DMI_MATCH(DMI_SYS_VENDOR, "MPMAN"),
841 DMI_MATCH(DMI_PRODUCT_NAME, "Converter9"),
842 },
843 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
844 BYT_RT5640_MONO_SPEAKER |
845 BYT_RT5640_SSP0_AIF1 |
846 BYT_RT5640_MCLK_EN),
847 },
Hans de Goedec8b78f22020-04-05 15:37:26 +0200848 {
849 /* MPMAN MPWIN895CL */
850 .matches = {
851 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MPMAN"),
852 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MPWIN8900CL"),
853 },
854 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
855 BYT_RT5640_MONO_SPEAKER |
856 BYT_RT5640_SSP0_AIF1 |
857 BYT_RT5640_MCLK_EN),
858 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200859 { /* MSI S100 tablet */
860 .matches = {
861 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
862 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "S100"),
863 },
864 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
865 BYT_RT5640_JD_SRC_JD2_IN4N |
866 BYT_RT5640_OVCD_TH_2000UA |
867 BYT_RT5640_OVCD_SF_0P75 |
868 BYT_RT5640_MONO_SPEAKER |
869 BYT_RT5640_DIFF_MIC |
870 BYT_RT5640_MCLK_EN),
871 },
Hans de Goede6cea3592018-06-03 15:42:31 +0200872 { /* Nuvison/TMax TM800W560 */
873 .matches = {
874 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TMAX"),
875 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TM800W560L"),
876 },
877 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
878 BYT_RT5640_JD_SRC_JD2_IN4N |
879 BYT_RT5640_OVCD_TH_2000UA |
880 BYT_RT5640_OVCD_SF_0P75 |
881 BYT_RT5640_JD_NOT_INV |
882 BYT_RT5640_DIFF_MIC |
883 BYT_RT5640_SSP0_AIF1 |
884 BYT_RT5640_MCLK_EN),
885 },
Hans de Goede260c48b2018-08-12 13:42:06 +0200886 { /* Onda v975w */
887 .matches = {
888 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
889 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
890 /* The above are too generic, also match BIOS info */
891 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "5.6.5"),
892 DMI_EXACT_MATCH(DMI_BIOS_DATE, "07/25/2014"),
893 },
894 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
895 BYT_RT5640_JD_SRC_JD2_IN4N |
896 BYT_RT5640_OVCD_TH_2000UA |
897 BYT_RT5640_OVCD_SF_0P75 |
898 BYT_RT5640_DIFF_MIC |
899 BYT_RT5640_MCLK_EN),
900 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200901 { /* Pipo W4 */
902 .matches = {
903 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
904 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
905 /* The above are too generic, also match BIOS info */
906 DMI_MATCH(DMI_BIOS_VERSION, "V8L_WIN32_CHIPHD"),
907 },
908 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
909 BYT_RT5640_MONO_SPEAKER |
910 BYT_RT5640_SSP0_AIF1 |
911 BYT_RT5640_MCLK_EN),
912 },
913 { /* Point of View Mobii TAB-P800W (V2.0) */
914 .matches = {
915 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
916 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
917 /* The above are too generic, also match BIOS info */
918 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1014"),
919 DMI_EXACT_MATCH(DMI_BIOS_DATE, "10/24/2014"),
920 },
921 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
922 BYT_RT5640_JD_SRC_JD2_IN4N |
923 BYT_RT5640_OVCD_TH_2000UA |
924 BYT_RT5640_OVCD_SF_0P75 |
925 BYT_RT5640_MONO_SPEAKER |
926 BYT_RT5640_DIFF_MIC |
927 BYT_RT5640_SSP0_AIF2 |
928 BYT_RT5640_MCLK_EN),
929 },
930 { /* Point of View Mobii TAB-P800W (V2.1) */
931 .matches = {
932 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
933 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
934 /* The above are too generic, also match BIOS info */
935 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1013"),
936 DMI_EXACT_MATCH(DMI_BIOS_DATE, "08/22/2014"),
937 },
938 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
939 BYT_RT5640_JD_SRC_JD2_IN4N |
940 BYT_RT5640_OVCD_TH_2000UA |
941 BYT_RT5640_OVCD_SF_0P75 |
942 BYT_RT5640_MONO_SPEAKER |
943 BYT_RT5640_DIFF_MIC |
944 BYT_RT5640_SSP0_AIF2 |
945 BYT_RT5640_MCLK_EN),
946 },
Hans de Goede02e5af62018-12-08 14:01:14 +0100947 { /* Point of View Mobii TAB-P1005W-232 (V2.0) */
948 .matches = {
949 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "POV"),
950 DMI_EXACT_MATCH(DMI_BOARD_NAME, "I102A"),
951 },
952 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
953 BYT_RT5640_JD_SRC_JD2_IN4N |
954 BYT_RT5640_OVCD_TH_2000UA |
955 BYT_RT5640_OVCD_SF_0P75 |
956 BYT_RT5640_DIFF_MIC |
957 BYT_RT5640_SSP0_AIF1 |
958 BYT_RT5640_MCLK_EN),
959 },
Irina Tirdea0565e772016-08-12 16:27:58 -0500960 {
Hans de Goede271248f2018-12-08 14:01:13 +0100961 /* Prowise PT301 */
962 .matches = {
963 DMI_MATCH(DMI_SYS_VENDOR, "Prowise"),
964 DMI_MATCH(DMI_PRODUCT_NAME, "PT301"),
965 },
966 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
967 BYT_RT5640_JD_SRC_JD2_IN4N |
968 BYT_RT5640_OVCD_TH_2000UA |
969 BYT_RT5640_OVCD_SF_0P75 |
970 BYT_RT5640_DIFF_MIC |
971 BYT_RT5640_SSP0_AIF1 |
972 BYT_RT5640_MCLK_EN),
973 },
974 {
Hans de Goede7eccc052019-12-03 23:14:42 +0100975 /* Teclast X89 */
Irina Tirdea0565e772016-08-12 16:27:58 -0500976 .matches = {
Pierre-Louis Bossartec1c90e2016-08-12 16:27:59 -0500977 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
978 DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
979 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500980 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
Hans de Goede7eccc052019-12-03 23:14:42 +0100981 BYT_RT5640_JD_SRC_JD1_IN4P |
982 BYT_RT5640_OVCD_TH_2000UA |
983 BYT_RT5640_OVCD_SF_1P0 |
984 BYT_RT5640_SSP0_AIF1 |
985 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossartec1c90e2016-08-12 16:27:59 -0500986 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200987 { /* Toshiba Satellite Click Mini L9W-B */
988 .matches = {
989 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
990 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
991 },
992 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
993 BYT_RT5640_JD_SRC_JD2_IN4N |
994 BYT_RT5640_OVCD_TH_1500UA |
995 BYT_RT5640_OVCD_SF_0P75 |
996 BYT_RT5640_SSP0_AIF1 |
997 BYT_RT5640_MCLK_EN),
998 },
Hans de Goede0e0e10f2020-05-18 09:24:16 +0200999 { /* Toshiba Encore WT8-A */
1000 .matches = {
1001 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1002 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"),
1003 },
1004 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
1005 BYT_RT5640_JD_SRC_JD2_IN4N |
1006 BYT_RT5640_OVCD_TH_2000UA |
1007 BYT_RT5640_OVCD_SF_0P75 |
1008 BYT_RT5640_JD_NOT_INV |
1009 BYT_RT5640_MCLK_EN),
1010 },
Hans de Goede199a5e82020-06-08 22:46:33 +02001011 { /* Toshiba Encore WT10-A */
1012 .matches = {
1013 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1014 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"),
1015 },
1016 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
1017 BYT_RT5640_JD_SRC_JD1_IN4P |
1018 BYT_RT5640_OVCD_TH_2000UA |
1019 BYT_RT5640_OVCD_SF_0P75 |
1020 BYT_RT5640_SSP0_AIF2 |
1021 BYT_RT5640_MCLK_EN),
1022 },
Hans de Goedee1317cc2021-02-16 22:35:53 +01001023 { /* Voyo Winpad A15 */
1024 .matches = {
1025 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
1026 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
1027 /* Above strings are too generic, also match on BIOS date */
1028 DMI_MATCH(DMI_BIOS_DATE, "11/20/2014"),
1029 },
1030 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
1031 BYT_RT5640_JD_SRC_JD2_IN4N |
1032 BYT_RT5640_OVCD_TH_2000UA |
1033 BYT_RT5640_OVCD_SF_0P75 |
1034 BYT_RT5640_DIFF_MIC |
1035 BYT_RT5640_MCLK_EN),
1036 },
Hans de Goede3c0d0112018-05-13 09:24:32 +02001037 { /* Catch-all for generic Insyde tablets, must be last */
youling25757180042017-01-04 15:44:53 -06001038 .matches = {
1039 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
1040 },
Hans de Goede96a388fe2018-05-13 09:24:30 +02001041 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001042 BYT_RT5640_MCLK_EN |
1043 BYT_RT5640_SSP0_AIF1),
youling25757180042017-01-04 15:44:53 -06001044
1045 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001046 {}
1047};
1048
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001049/*
1050 * Note this MUST be called before snd_soc_register_card(), so that the props
1051 * are in place before the codec component driver's probe function parses them.
1052 */
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001053static int byt_rt5640_add_codec_device_props(struct device *i2c_dev,
1054 struct byt_rt5640_private *priv)
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001055{
1056 struct property_entry props[MAX_NO_PROPS] = {};
Heikki Krogerus0bd3c072021-08-13 10:11:16 -05001057 struct fwnode_handle *fwnode;
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001058 int cnt = 0;
Heikki Krogerus0bd3c072021-08-13 10:11:16 -05001059 int ret;
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001060
1061 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
Hans de Goedea3ad2912018-05-13 09:24:26 +02001062 case BYT_RT5640_DMIC1_MAP:
1063 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin",
1064 RT5640_DMIC1_DATA_PIN_IN1P);
1065 break;
1066 case BYT_RT5640_DMIC2_MAP:
1067 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin",
1068 RT5640_DMIC2_DATA_PIN_IN1N);
1069 break;
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001070 case BYT_RT5640_IN1_MAP:
1071 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
1072 props[cnt++] =
1073 PROPERTY_ENTRY_BOOL("realtek,in1-differential");
1074 break;
1075 case BYT_RT5640_IN3_MAP:
1076 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
1077 props[cnt++] =
1078 PROPERTY_ENTRY_BOOL("realtek,in3-differential");
1079 break;
1080 }
1081
Hans de Goede77323102018-05-13 09:24:28 +02001082 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
1083 props[cnt++] = PROPERTY_ENTRY_U32(
1084 "realtek,jack-detect-source",
1085 BYT_RT5640_JDSRC(byt_rt5640_quirk));
1086
1087 props[cnt++] = PROPERTY_ENTRY_U32(
1088 "realtek,over-current-threshold-microamp",
1089 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
1090
1091 props[cnt++] = PROPERTY_ENTRY_U32(
1092 "realtek,over-current-scale-factor",
1093 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
1094 }
1095
1096 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
1097 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted");
1098
Heikki Krogerus0bd3c072021-08-13 10:11:16 -05001099 fwnode = fwnode_create_software_node(props, NULL);
1100 if (IS_ERR(fwnode)) {
1101 /* put_device() is handled in caller */
1102 return PTR_ERR(fwnode);
1103 }
1104
1105 ret = device_add_software_node(i2c_dev, to_software_node(fwnode));
1106
1107 fwnode_handle_put(fwnode);
1108
1109 return ret;
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001110}
1111
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001112static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
1113{
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001114 struct snd_soc_card *card = runtime->card;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001115 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +09001116 struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
Hans de Goede46466ab2021-01-09 22:01:18 +01001117 const struct snd_soc_dapm_route *custom_map = NULL;
1118 int num_routes = 0;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001119 int ret;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001120
1121 card->dapm.idle_bias_off = true;
1122
Hans de Goede77323102018-05-13 09:24:28 +02001123 /* Start with RC clk for jack-detect (we disable MCLK below) */
1124 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
1125 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
1126 RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_RCCLK);
1127
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001128 rt5640_sel_asrc_clk_src(component,
Pierre-Louis Bossart0ec66e2d2016-01-04 17:20:27 -06001129 RT5640_DA_STEREO_FILTER |
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001130 RT5640_DA_MONO_L_FILTER |
1131 RT5640_DA_MONO_R_FILTER |
1132 RT5640_AD_STEREO_FILTER |
1133 RT5640_AD_MONO_L_FILTER |
1134 RT5640_AD_MONO_R_FILTER,
Pierre-Louis Bossart0ec66e2d2016-01-04 17:20:27 -06001135 RT5640_CLK_SEL_ASRC);
1136
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001137 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
1138 ARRAY_SIZE(byt_rt5640_controls));
1139 if (ret) {
1140 dev_err(card->dev, "unable to add card controls\n");
1141 return ret;
1142 }
1143
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001144 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
1145 case BYT_RT5640_IN1_MAP:
1146 custom_map = byt_rt5640_intmic_in1_map;
1147 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
1148 break;
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -05001149 case BYT_RT5640_IN3_MAP:
1150 custom_map = byt_rt5640_intmic_in3_map;
1151 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
1152 break;
Hans de Goede46466ab2021-01-09 22:01:18 +01001153 case BYT_RT5640_DMIC1_MAP:
1154 custom_map = byt_rt5640_intmic_dmic1_map;
1155 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
1156 break;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001157 case BYT_RT5640_DMIC2_MAP:
1158 custom_map = byt_rt5640_intmic_dmic2_map;
1159 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
1160 break;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001161 }
1162
1163 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
1164 if (ret)
1165 return ret;
1166
Hans de Goede79c1123b2021-08-02 16:25:00 +02001167 if (byt_rt5640_quirk & BYT_RT5640_HSMIC2_ON_IN1) {
1168 ret = snd_soc_dapm_add_routes(&card->dapm,
Hans de Goede0a61bcb2021-08-19 21:05:42 +02001169 byt_rt5640_hsmic2_in1_map,
1170 ARRAY_SIZE(byt_rt5640_hsmic2_in1_map));
Hans de Goede79c1123b2021-08-02 16:25:00 +02001171 if (ret)
1172 return ret;
1173 }
1174
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -05001175 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
1176 ret = snd_soc_dapm_add_routes(&card->dapm,
1177 byt_rt5640_ssp2_aif2_map,
1178 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001179 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
1180 ret = snd_soc_dapm_add_routes(&card->dapm,
1181 byt_rt5640_ssp0_aif1_map,
1182 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
1183 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
1184 ret = snd_soc_dapm_add_routes(&card->dapm,
1185 byt_rt5640_ssp0_aif2_map,
1186 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -05001187 } else {
1188 ret = snd_soc_dapm_add_routes(&card->dapm,
1189 byt_rt5640_ssp2_aif1_map,
1190 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
1191 }
1192 if (ret)
1193 return ret;
1194
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -05001195 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1196 ret = snd_soc_dapm_add_routes(&card->dapm,
1197 byt_rt5640_mono_spk_map,
1198 ARRAY_SIZE(byt_rt5640_mono_spk_map));
Hans de Goede1851ccf2021-01-09 22:01:17 +01001199 } else if (!(byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)) {
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -05001200 ret = snd_soc_dapm_add_routes(&card->dapm,
1201 byt_rt5640_stereo_spk_map,
1202 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
1203 }
1204 if (ret)
1205 return ret;
1206
Hans de Goededd3e2022021-08-02 16:24:57 +02001207 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT) {
1208 ret = snd_soc_dapm_add_routes(&card->dapm,
1209 byt_rt5640_lineout_map,
1210 ARRAY_SIZE(byt_rt5640_lineout_map));
1211 if (ret)
1212 return ret;
1213 }
1214
Andy Shevchenkoa15ca6e2021-10-07 19:57:14 +03001215 /*
1216 * The firmware might enable the clock at boot (this information
1217 * may or may not be reflected in the enable clock register).
1218 * To change the rate we must disable the clock first to cover
1219 * these cases. Due to common clock framework restrictions that
1220 * do not allow to disable a clock that has not been enabled,
1221 * we need to enable the clock first.
1222 */
1223 ret = clk_prepare_enable(priv->mclk);
1224 if (!ret)
1225 clk_disable_unprepare(priv->mclk);
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001226
Andy Shevchenkoa15ca6e2021-10-07 19:57:14 +03001227 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
1228 ret = clk_set_rate(priv->mclk, 25000000);
1229 else
1230 ret = clk_set_rate(priv->mclk, 19200000);
1231 if (ret) {
1232 dev_err(card->dev, "unable to set MCLK rate\n");
1233 return ret;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001234 }
1235
Hans de Goede77323102018-05-13 09:24:28 +02001236 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
1237 ret = snd_soc_card_jack_new(card, "Headset",
1238 SND_JACK_HEADSET | SND_JACK_BTN_0,
1239 &priv->jack, rt5640_pins,
1240 ARRAY_SIZE(rt5640_pins));
1241 if (ret) {
1242 dev_err(card->dev, "Jack creation failed %d\n", ret);
1243 return ret;
1244 }
1245 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
1246 KEY_PLAYPAUSE);
1247 snd_soc_component_set_jack(component, &priv->jack, NULL);
1248 }
1249
Hans de Goede9ba00852021-08-19 21:05:43 +02001250 if (byt_rt5640_quirk & BYT_RT5640_JD_HP_ELITEP_1000G2) {
1251 ret = snd_soc_card_jack_new(card, "Headset",
1252 SND_JACK_HEADSET,
1253 &priv->jack, rt5640_pins,
1254 ARRAY_SIZE(rt5640_pins));
1255 if (ret)
1256 return ret;
1257
1258 ret = snd_soc_card_jack_new(card, "Headset 2",
1259 SND_JACK_HEADSET,
1260 &priv->jack2, rt5640_pins2,
1261 ARRAY_SIZE(rt5640_pins2));
1262 if (ret)
1263 return ret;
1264
1265 rt5640_jack_gpio.data = priv;
1266 rt5640_jack_gpio.gpiod_dev = priv->codec_dev;
1267 rt5640_jack_gpio.jack_status_check = byt_rt5640_hp_elitepad_1000g2_jack1_check;
1268 ret = snd_soc_jack_add_gpios(&priv->jack, 1, &rt5640_jack_gpio);
1269 if (ret)
1270 return ret;
1271
1272 rt5640_set_ovcd_params(component);
1273 rt5640_jack2_gpio.data = component;
1274 rt5640_jack2_gpio.gpiod_dev = priv->codec_dev;
1275 rt5640_jack2_gpio.jack_status_check = byt_rt5640_hp_elitepad_1000g2_jack2_check;
1276 ret = snd_soc_jack_add_gpios(&priv->jack2, 1, &rt5640_jack2_gpio);
1277 if (ret) {
1278 snd_soc_jack_free_gpios(&priv->jack, 1, &rt5640_jack_gpio);
1279 return ret;
1280 }
1281 }
1282
Hans de Goede77323102018-05-13 09:24:28 +02001283 return 0;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001284}
1285
Hans de Goede9ba00852021-08-19 21:05:43 +02001286static void byt_rt5640_exit(struct snd_soc_pcm_runtime *runtime)
1287{
1288 struct snd_soc_card *card = runtime->card;
1289 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1290
1291 if (byt_rt5640_quirk & BYT_RT5640_JD_HP_ELITEP_1000G2) {
1292 snd_soc_jack_free_gpios(&priv->jack2, 1, &rt5640_jack2_gpio);
1293 snd_soc_jack_free_gpios(&priv->jack, 1, &rt5640_jack_gpio);
1294 }
1295}
1296
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001297static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301298 struct snd_pcm_hw_params *params)
1299{
1300 struct snd_interval *rate = hw_param_interval(params,
1301 SNDRV_PCM_HW_PARAM_RATE);
1302 struct snd_interval *channels = hw_param_interval(params,
1303 SNDRV_PCM_HW_PARAM_CHANNELS);
Erik Bussing332719b2020-01-15 17:46:16 +01001304 int ret, bits;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301305
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001306 /* The DSP will covert the FE rate to 48k, stereo */
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301307 rate->min = rate->max = 48000;
1308 channels->min = channels->max = 2;
1309
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001310 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
Erik Bussing332719b2020-01-15 17:46:16 +01001311 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
Pierre-Louis Bossart8f98307d2016-08-16 18:28:22 -05001312 /* set SSP0 to 16-bit */
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001313 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
Erik Bussing332719b2020-01-15 17:46:16 +01001314 bits = 16;
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001315 } else {
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -05001316 /* set SSP2 to 24-bit */
1317 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
Erik Bussing332719b2020-01-15 17:46:16 +01001318 bits = 24;
Sebastien Guiriec3f27ded2015-12-17 20:35:39 -06001319 }
Erik Bussing332719b2020-01-15 17:46:16 +01001320
1321 /*
1322 * Default mode for SSP configuration is TDM 4 slot, override config
1323 * with explicit setting to I2S 2ch. The word length is set with
1324 * dai_set_tdm_slot() since there is no other API exposed
1325 */
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +09001326 ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
Erik Bussing332719b2020-01-15 17:46:16 +01001327 SND_SOC_DAIFMT_I2S |
1328 SND_SOC_DAIFMT_NB_NF |
Peter Ujfalusi5374b922021-09-20 09:55:08 +03001329 SND_SOC_DAIFMT_CBC_CFC);
Erik Bussing332719b2020-01-15 17:46:16 +01001330 if (ret < 0) {
1331 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
1332 return ret;
1333 }
1334
Kuninori Morimoto0d1571c2020-03-23 14:19:05 +09001335 ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);
Erik Bussing332719b2020-01-15 17:46:16 +01001336 if (ret < 0) {
1337 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
1338 return ret;
1339 }
1340
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301341 return 0;
1342}
1343
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001344static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301345{
Lars-Peter Clausend0a1b662015-10-18 15:39:30 +02001346 return snd_pcm_hw_constraint_single(substream->runtime,
1347 SNDRV_PCM_HW_PARAM_RATE, 48000);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301348}
1349
Julia Lawall9b6fdef2016-10-15 16:55:49 +02001350static const struct snd_soc_ops byt_rt5640_aif1_ops = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001351 .startup = byt_rt5640_aif1_startup,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301352};
1353
Julia Lawall9b6fdef2016-10-15 16:55:49 +02001354static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001355 .hw_params = byt_rt5640_aif1_hw_params,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301356};
1357
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001358SND_SOC_DAILINK_DEF(dummy,
1359 DAILINK_COMP_ARRAY(COMP_DUMMY()));
1360
1361SND_SOC_DAILINK_DEF(media,
1362 DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
1363
1364SND_SOC_DAILINK_DEF(deepbuffer,
1365 DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
1366
1367SND_SOC_DAILINK_DEF(ssp2_port,
1368 /* overwritten for ssp0 routing */
1369 DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
1370SND_SOC_DAILINK_DEF(ssp2_codec,
1371 DAILINK_COMP_ARRAY(COMP_CODEC(
1372 /* overwritten with HID */ "i2c-10EC5640:00",
1373 /* changed w/ quirk */ "rt5640-aif1")));
1374
1375SND_SOC_DAILINK_DEF(platform,
1376 DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
1377
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001378static struct snd_soc_dai_link byt_rt5640_dais[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301379 [MERR_DPCM_AUDIO] = {
1380 .name = "Baytrail Audio Port",
1381 .stream_name = "Baytrail Audio",
Takashi Iwai6e4cac22017-04-24 14:09:55 +02001382 .nonatomic = true,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301383 .dynamic = 1,
1384 .dpcm_playback = 1,
1385 .dpcm_capture = 1,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001386 .ops = &byt_rt5640_aif1_ops,
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001387 SND_SOC_DAILINK_REG(media, dummy, platform),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301388 },
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001389 [MERR_DPCM_DEEP_BUFFER] = {
1390 .name = "Deep-Buffer Audio Port",
1391 .stream_name = "Deep-Buffer Audio",
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001392 .nonatomic = true,
1393 .dynamic = 1,
1394 .dpcm_playback = 1,
1395 .ops = &byt_rt5640_aif1_ops,
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001396 SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001397 },
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301398 /* back ends */
1399 {
1400 .name = "SSP2-Codec",
Pierre-Louis Bossart149f7752017-10-12 18:38:04 -05001401 .id = 0,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301402 .no_pcm = 1,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301403 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Peter Ujfalusi5374b922021-09-20 09:55:08 +03001404 | SND_SOC_DAIFMT_CBC_CFC,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001405 .be_hw_params_fixup = byt_rt5640_codec_fixup,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301406 .dpcm_playback = 1,
1407 .dpcm_capture = 1,
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001408 .init = byt_rt5640_init,
Hans de Goede9ba00852021-08-19 21:05:43 +02001409 .exit = byt_rt5640_exit,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001410 .ops = &byt_rt5640_be_ssp2_ops,
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001411 SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301412 },
1413};
1414
1415/* SoC card */
Hans de Goede77323102018-05-13 09:24:28 +02001416static char byt_rt5640_codec_name[SND_ACPI_I2C_ID_LEN];
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001417#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
Hans de Goede063422c2018-05-13 09:24:35 +02001418static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001419#endif
Hans de Goededd3e2022021-08-02 16:24:57 +02001420static char byt_rt5640_components[64]; /* = "cfg-spk:* cfg-mic:* ..." */
Hans de Goede77323102018-05-13 09:24:28 +02001421
1422static int byt_rt5640_suspend(struct snd_soc_card *card)
1423{
1424 struct snd_soc_component *component;
1425
1426 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1427 return 0;
1428
Kuninori Morimotof70f18f72018-09-18 01:29:55 +00001429 for_each_card_components(card, component) {
Hans de Goede77323102018-05-13 09:24:28 +02001430 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1431 dev_dbg(component->dev, "disabling jack detect before suspend\n");
1432 snd_soc_component_set_jack(component, NULL, NULL);
1433 break;
1434 }
1435 }
1436
1437 return 0;
1438}
1439
1440static int byt_rt5640_resume(struct snd_soc_card *card)
1441{
1442 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1443 struct snd_soc_component *component;
1444
1445 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1446 return 0;
1447
Kuninori Morimotof70f18f72018-09-18 01:29:55 +00001448 for_each_card_components(card, component) {
Hans de Goede77323102018-05-13 09:24:28 +02001449 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1450 dev_dbg(component->dev, "re-enabling jack detect after resume\n");
1451 snd_soc_component_set_jack(component, &priv->jack, NULL);
1452 break;
1453 }
1454 }
1455
1456 return 0;
1457}
1458
Pierre-Louis Bossartb4ecd582020-06-17 11:56:14 -05001459/* use space before codec name to simplify card ID, and simplify driver name */
Pierre-Louis Bossart41656c32020-11-12 16:38:16 -06001460#define SOF_CARD_NAME "bytcht rt5640" /* card name will be 'sof-bytcht rt5640' */
1461#define SOF_DRIVER_NAME "SOF"
1462
Pierre-Louis Bossartb4ecd582020-06-17 11:56:14 -05001463#define CARD_NAME "bytcr-rt5640"
1464#define DRIVER_NAME NULL /* card name will be used for driver name */
Pierre-Louis Bossartb4ecd582020-06-17 11:56:14 -05001465
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001466static struct snd_soc_card byt_rt5640_card = {
Axel Lin54d86972015-08-21 20:59:21 +08001467 .owner = THIS_MODULE,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001468 .dai_link = byt_rt5640_dais,
1469 .num_links = ARRAY_SIZE(byt_rt5640_dais),
1470 .dapm_widgets = byt_rt5640_widgets,
1471 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
1472 .dapm_routes = byt_rt5640_audio_map,
1473 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001474 .fully_routed = true,
Hans de Goede77323102018-05-13 09:24:28 +02001475 .suspend_pre = byt_rt5640_suspend,
1476 .resume_post = byt_rt5640_resume,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301477};
1478
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001479struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
1480 u64 aif_value; /* 1: AIF1, 2: AIF2 */
1481 u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
1482};
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001483
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001484static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301485{
Pierre-Louis Bossart05ff3122020-11-12 16:38:17 -06001486 struct device *dev = &pdev->dev;
Hans de Goede46466ab2021-01-09 22:01:18 +01001487 static const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3", "none" };
Andy Shevchenkoe86c18932021-10-07 19:57:12 +03001488 struct snd_soc_acpi_mach *mach = dev_get_platdata(dev);
Hans de Goede1851ccf2021-01-09 22:01:17 +01001489 __maybe_unused const char *spk_type;
Hans de Goede6d1bfcc2018-05-13 09:24:33 +02001490 const struct dmi_system_id *dmi_id;
Hans de Goede79c1123b2021-08-02 16:25:00 +02001491 const char *headset2_string = "";
Hans de Goededd3e2022021-08-02 16:24:57 +02001492 const char *lineout_string = "";
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001493 struct byt_rt5640_private *priv;
Pierre-Louis Bossartbd7661b2019-01-25 14:34:59 -06001494 const char *platform_name;
Andy Shevchenkoa320d892019-03-28 19:17:25 +02001495 struct acpi_device *adev;
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001496 struct device *codec_dev;
Pierre-Louis Bossart41656c32020-11-12 16:38:16 -06001497 bool sof_parent;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001498 int ret_val = 0;
Pierre-Louis Bossart2193eb92017-10-12 18:38:05 -05001499 int dai_index = 0;
Hans de Goede1851ccf2021-01-09 22:01:17 +01001500 int i, cfg_spk;
Hans de Goede9f47c9c2021-03-07 16:05:03 +01001501 int aif;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001502
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -05001503 is_bytcr = false;
Andy Shevchenko81d43ca12021-10-07 19:57:13 +03001504 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001505 if (!priv)
1506 return -ENOMEM;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301507
1508 /* register the soc card */
Andy Shevchenko81d43ca12021-10-07 19:57:13 +03001509 byt_rt5640_card.dev = dev;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001510 snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001511
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001512 /* fix index of codec dai */
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001513 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001514 if (!strcmp(byt_rt5640_dais[i].codecs->name,
1515 "i2c-10EC5640:00")) {
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001516 dai_index = i;
1517 break;
1518 }
1519 }
1520
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001521 /* fixup codec name based on HID */
Andy Shevchenkoa320d892019-03-28 19:17:25 +02001522 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
1523 if (adev) {
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001524 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
Andy Shevchenkoa320d892019-03-28 19:17:25 +02001525 "i2c-%s", acpi_dev_name(adev));
1526 put_device(&adev->dev);
Kuninori Morimotoe7a71282019-06-06 13:20:44 +09001527 byt_rt5640_dais[dai_index].codecs->name = byt_rt5640_codec_name;
Pierre-Louis Bossart69efe3b2021-08-13 10:11:10 -05001528 } else {
Andy Shevchenko81d43ca12021-10-07 19:57:13 +03001529 dev_err(dev, "Error cannot find '%s' dev\n", mach->id);
Pierre-Louis Bossart69efe3b2021-08-13 10:11:10 -05001530 return -ENXIO;
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001531 }
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301532
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001533 /*
1534 * swap SSP0 if bytcr is detected
1535 * (will be overridden if DMI quirk is detected)
1536 */
Pierre-Louis Bossart536cfd22019-05-30 06:50:11 -05001537 if (soc_intel_is_byt()) {
Pierre-Louis Bossart3ee1cd42018-11-01 16:34:50 -05001538 if (mach->mach_params.acpi_ipc_irq_index == 0)
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001539 is_bytcr = true;
1540 }
1541
1542 if (is_bytcr) {
1543 /*
1544 * Baytrail CR platforms may have CHAN package in BIOS, try
1545 * to find relevant routing quirk based as done on Windows
1546 * platforms. We have to read the information directly from the
1547 * BIOS, at this stage the card is not created and the links
1548 * with the codec driver/pdata are non-existent
1549 */
1550
1551 struct acpi_chan_package chan_package;
1552
1553 /* format specified: 2 64-bit integers */
1554 struct acpi_buffer format = {sizeof("NN"), "NN"};
1555 struct acpi_buffer state = {0, NULL};
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001556 struct snd_soc_acpi_package_context pkg_ctx;
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001557 bool pkg_found = false;
1558
1559 state.length = sizeof(chan_package);
1560 state.pointer = &chan_package;
1561
1562 pkg_ctx.name = "CHAN";
1563 pkg_ctx.length = 2;
1564 pkg_ctx.format = &format;
1565 pkg_ctx.state = &state;
1566 pkg_ctx.data_valid = false;
1567
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001568 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
1569 &pkg_ctx);
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001570 if (pkg_found) {
1571 if (chan_package.aif_value == 1) {
Andy Shevchenko81d43ca12021-10-07 19:57:13 +03001572 dev_info(dev, "BIOS Routing: AIF1 connected\n");
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001573 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
1574 } else if (chan_package.aif_value == 2) {
Andy Shevchenko81d43ca12021-10-07 19:57:13 +03001575 dev_info(dev, "BIOS Routing: AIF2 connected\n");
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001576 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1577 } else {
Andy Shevchenko81d43ca12021-10-07 19:57:13 +03001578 dev_info(dev, "BIOS Routing isn't valid, ignored\n");
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001579 pkg_found = false;
1580 }
1581 }
1582
1583 if (!pkg_found) {
1584 /* no BIOS indications, assume SSP0-AIF2 connection */
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001585 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1586 }
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -06001587
1588 /* change defaults for Baytrail-CR capture */
Hans de Goede96a388fe2018-05-13 09:24:30 +02001589 byt_rt5640_quirk |= BYTCR_INPUT_DEFAULTS;
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -06001590 } else {
Hans de Goede56ff4402018-05-13 09:24:31 +02001591 byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP |
1592 BYT_RT5640_JD_SRC_JD2_IN4N |
1593 BYT_RT5640_OVCD_TH_2000UA |
1594 BYT_RT5640_OVCD_SF_0P75;
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001595 }
1596
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -06001597 /* check quirks before creating card */
Hans de Goede6d1bfcc2018-05-13 09:24:33 +02001598 dmi_id = dmi_first_match(byt_rt5640_quirk_table);
1599 if (dmi_id)
1600 byt_rt5640_quirk = (unsigned long)dmi_id->driver_data;
Pierre-Louis Bossart2fb2a192019-04-19 15:12:17 -05001601 if (quirk_override != -1) {
Andy Shevchenko81d43ca12021-10-07 19:57:13 +03001602 dev_info(dev, "Overriding quirk 0x%lx => 0x%x\n",
Pierre-Louis Bossart2697f3a2020-06-25 14:12:57 -05001603 byt_rt5640_quirk, quirk_override);
Takashi Iwai9f2cf732017-04-23 09:22:56 +02001604 byt_rt5640_quirk = quirk_override;
1605 }
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001606
Pierre-Louis Bossartd3409eb2021-08-13 10:11:11 -05001607 codec_dev = acpi_get_first_physical_node(adev);
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001608 if (!codec_dev)
1609 return -EPROBE_DEFER;
Pierre-Louis Bossartd3409eb2021-08-13 10:11:11 -05001610 priv->codec_dev = get_device(codec_dev);
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001611
Hans de Goede9ba00852021-08-19 21:05:43 +02001612 if (byt_rt5640_quirk & BYT_RT5640_JD_HP_ELITEP_1000G2) {
1613 acpi_dev_add_driver_gpios(ACPI_COMPANION(priv->codec_dev),
1614 byt_rt5640_hp_elitepad_1000g2_gpios);
1615
Andy Shevchenko81d43ca12021-10-07 19:57:13 +03001616 priv->hsmic_detect = devm_fwnode_gpiod_get(dev, codec_dev->fwnode,
Hans de Goede9ba00852021-08-19 21:05:43 +02001617 "headset-mic-detect", GPIOD_IN,
1618 "headset-mic-detect");
1619 if (IS_ERR(priv->hsmic_detect)) {
Andy Shevchenkoee233502021-10-07 19:57:15 +03001620 ret_val = dev_err_probe(dev, PTR_ERR(priv->hsmic_detect),
1621 "getting hsmic-detect GPIO\n");
Hans de Goede9ba00852021-08-19 21:05:43 +02001622 goto err_device;
1623 }
1624 }
1625
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001626 /* Must be called before register_card, also see declaration comment. */
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001627 ret_val = byt_rt5640_add_codec_device_props(codec_dev, priv);
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001628 if (ret_val)
Hans de Goede9ba00852021-08-19 21:05:43 +02001629 goto err_remove_gpios;
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001630
Andy Shevchenko81d43ca12021-10-07 19:57:13 +03001631 log_quirks(dev);
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -06001632
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001633 if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
Hans de Goede9f47c9c2021-03-07 16:05:03 +01001634 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
Nariman Etemadi29686832020-01-15 17:46:17 +01001635 byt_rt5640_dais[dai_index].codecs->dai_name = "rt5640-aif2";
Hans de Goede9f47c9c2021-03-07 16:05:03 +01001636 aif = 2;
1637 } else {
1638 aif = 1;
1639 }
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -05001640
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001641 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
Nariman Etemadi29686832020-01-15 17:46:17 +01001642 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2))
1643 byt_rt5640_dais[dai_index].cpus->dai_name = "ssp0-port";
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001644
Pierre-Louis Bossart7735bce2017-09-08 12:43:52 -05001645 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
Andy Shevchenkoa15ca6e2021-10-07 19:57:14 +03001646 priv->mclk = devm_clk_get_optional(dev, "pmc_plt_clk_3");
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001647 if (IS_ERR(priv->mclk)) {
Andy Shevchenkoee233502021-10-07 19:57:15 +03001648 ret_val = dev_err_probe(dev, PTR_ERR(priv->mclk),
1649 "Failed to get MCLK from pmc_plt_clk_3\n");
Andy Shevchenkoa15ca6e2021-10-07 19:57:14 +03001650 goto err;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001651 }
Andy Shevchenkoa15ca6e2021-10-07 19:57:14 +03001652 /*
1653 * Fall back to bit clock usage when clock is not
1654 * available likely due to missing dependencies.
1655 */
1656 if (!priv->mclk)
1657 byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001658 }
1659
Hans de Goede1851ccf2021-01-09 22:01:17 +01001660 if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS) {
1661 cfg_spk = 0;
1662 spk_type = "none";
1663 } else if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1664 cfg_spk = 1;
1665 spk_type = "mono";
1666 } else {
1667 cfg_spk = 2;
1668 spk_type = "stereo";
1669 }
1670
Hans de Goede044c7652021-08-02 16:24:59 +02001671 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT) {
1672 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT_AS_HP2)
1673 lineout_string = " cfg-hp2:lineout";
1674 else
Hans de Goedef8043ef2021-08-16 13:47:22 +02001675 lineout_string = " cfg-lineout:2";
Hans de Goede044c7652021-08-02 16:24:59 +02001676 }
Hans de Goededd3e2022021-08-02 16:24:57 +02001677
Hans de Goede79c1123b2021-08-02 16:25:00 +02001678 if (byt_rt5640_quirk & BYT_RT5640_HSMIC2_ON_IN1)
1679 headset2_string = " cfg-hs2:in1";
1680
Jaroslav Kysela0d5c8182019-12-04 15:15:45 -06001681 snprintf(byt_rt5640_components, sizeof(byt_rt5640_components),
Hans de Goede79c1123b2021-08-02 16:25:00 +02001682 "cfg-spk:%d cfg-mic:%s aif:%d%s%s", cfg_spk,
Hans de Goededd3e2022021-08-02 16:24:57 +02001683 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)], aif,
Hans de Goede79c1123b2021-08-02 16:25:00 +02001684 lineout_string, headset2_string);
Jaroslav Kysela0d5c8182019-12-04 15:15:45 -06001685 byt_rt5640_card.components = byt_rt5640_components;
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001686#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
Hans de Goede063422c2018-05-13 09:24:35 +02001687 snprintf(byt_rt5640_long_name, sizeof(byt_rt5640_long_name),
Hans de Goede1851ccf2021-01-09 22:01:17 +01001688 "bytcr-rt5640-%s-spk-%s-mic", spk_type,
Hans de Goede063422c2018-05-13 09:24:35 +02001689 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1690 byt_rt5640_card.long_name = byt_rt5640_long_name;
Jaroslav Kyselab5706f82019-12-04 15:15:46 -06001691#endif
Hans de Goede063422c2018-05-13 09:24:35 +02001692
Pierre-Louis Bossartbd7661b2019-01-25 14:34:59 -06001693 /* override plaform name, if required */
1694 platform_name = mach->mach_params.platform;
1695
1696 ret_val = snd_soc_fixup_dai_links_platform_name(&byt_rt5640_card,
1697 platform_name);
1698 if (ret_val)
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001699 goto err;
Pierre-Louis Bossartbd7661b2019-01-25 14:34:59 -06001700
Andy Shevchenko81d43ca12021-10-07 19:57:13 +03001701 sof_parent = snd_soc_acpi_sof_parent(dev);
Pierre-Louis Bossart41656c32020-11-12 16:38:16 -06001702
1703 /* set card and driver name */
1704 if (sof_parent) {
1705 byt_rt5640_card.name = SOF_CARD_NAME;
1706 byt_rt5640_card.driver_name = SOF_DRIVER_NAME;
1707 } else {
1708 byt_rt5640_card.name = CARD_NAME;
1709 byt_rt5640_card.driver_name = DRIVER_NAME;
1710 }
1711
Pierre-Louis Bossart05ff3122020-11-12 16:38:17 -06001712 /* set pm ops */
1713 if (sof_parent)
1714 dev->driver->pm = &snd_soc_pm_ops;
1715
Andy Shevchenko81d43ca12021-10-07 19:57:13 +03001716 ret_val = devm_snd_soc_register_card(dev, &byt_rt5640_card);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301717 if (ret_val) {
Andy Shevchenko81d43ca12021-10-07 19:57:13 +03001718 dev_err(dev, "devm_snd_soc_register_card failed %d\n", ret_val);
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001719 goto err;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301720 }
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001721 platform_set_drvdata(pdev, &byt_rt5640_card);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301722 return ret_val;
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001723
1724err:
Heikki Krogerus0bd3c072021-08-13 10:11:16 -05001725 device_remove_software_node(priv->codec_dev);
Hans de Goede9ba00852021-08-19 21:05:43 +02001726err_remove_gpios:
1727 if (byt_rt5640_quirk & BYT_RT5640_JD_HP_ELITEP_1000G2)
1728 acpi_dev_remove_driver_gpios(ACPI_COMPANION(priv->codec_dev));
Pierre-Louis Bossartf1f8a962021-08-13 10:11:15 -05001729err_device:
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001730 put_device(priv->codec_dev);
1731 return ret_val;
1732}
1733
1734static int snd_byt_rt5640_mc_remove(struct platform_device *pdev)
1735{
1736 struct snd_soc_card *card = platform_get_drvdata(pdev);
1737 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1738
Hans de Goede9ba00852021-08-19 21:05:43 +02001739 if (byt_rt5640_quirk & BYT_RT5640_JD_HP_ELITEP_1000G2)
1740 acpi_dev_remove_driver_gpios(ACPI_COMPANION(priv->codec_dev));
1741
Heikki Krogerus0bd3c072021-08-13 10:11:16 -05001742 device_remove_software_node(priv->codec_dev);
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001743 put_device(priv->codec_dev);
1744 return 0;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301745}
1746
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001747static struct platform_driver snd_byt_rt5640_mc_driver = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301748 .driver = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001749 .name = "bytcr_rt5640",
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301750 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001751 .probe = snd_byt_rt5640_mc_probe,
Pierre-Louis Bossartc50f1262021-08-13 10:11:09 -05001752 .remove = snd_byt_rt5640_mc_remove,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301753};
1754
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001755module_platform_driver(snd_byt_rt5640_mc_driver);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301756
1757MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
1758MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
1759MODULE_LICENSE("GPL v2");
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001760MODULE_ALIAS("platform:bytcr_rt5640");