Thomas Gleixner | 8e8e69d | 2019-05-29 07:17:59 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 2 | /* |
| 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. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 9 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 | */ |
| 11 | |
Hans de Goede | 6a7c05e | 2018-05-08 17:35:54 +0200 | [diff] [blame] | 12 | #include <linux/i2c.h> |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
Takashi Iwai | 9f2cf73 | 2017-04-23 09:22:56 +0200 | [diff] [blame] | 15 | #include <linux/moduleparam.h> |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 17 | #include <linux/acpi.h> |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 18 | #include <linux/clk.h> |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 19 | #include <linux/device.h> |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 20 | #include <linux/dmi.h> |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 21 | #include <linux/input.h> |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 22 | #include <linux/slab.h> |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 23 | #include <sound/pcm.h> |
| 24 | #include <sound/pcm_params.h> |
| 25 | #include <sound/soc.h> |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 26 | #include <sound/jack.h> |
Pierre-Louis Bossart | 7feb2f7 | 2017-10-12 18:49:38 -0500 | [diff] [blame] | 27 | #include <sound/soc-acpi.h> |
Hans de Goede | a3ad291 | 2018-05-13 09:24:26 +0200 | [diff] [blame] | 28 | #include <dt-bindings/sound/rt5640.h> |
Jie Yang | e56c72d | 2015-04-02 15:37:02 +0800 | [diff] [blame] | 29 | #include "../../codecs/rt5640.h" |
Jie Yang | b97169d | 2015-04-02 15:37:04 +0800 | [diff] [blame] | 30 | #include "../atom/sst-atom-controls.h" |
Pierre-Louis Bossart | 536cfd2 | 2019-05-30 06:50:11 -0500 | [diff] [blame] | 31 | #include "../common/soc-intel-quirks.h" |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 32 | |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 33 | enum { |
| 34 | BYT_RT5640_DMIC1_MAP, |
| 35 | BYT_RT5640_DMIC2_MAP, |
| 36 | BYT_RT5640_IN1_MAP, |
Pierre-Louis Bossart | 59e8b65 | 2016-08-12 16:27:54 -0500 | [diff] [blame] | 37 | BYT_RT5640_IN3_MAP, |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 38 | }; |
| 39 | |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 40 | enum { |
| 41 | BYT_RT5640_JD_SRC_GPIO1 = (RT5640_JD_SRC_GPIO1 << 4), |
| 42 | BYT_RT5640_JD_SRC_JD1_IN4P = (RT5640_JD_SRC_JD1_IN4P << 4), |
| 43 | BYT_RT5640_JD_SRC_JD2_IN4N = (RT5640_JD_SRC_JD2_IN4N << 4), |
| 44 | BYT_RT5640_JD_SRC_GPIO2 = (RT5640_JD_SRC_GPIO2 << 4), |
| 45 | BYT_RT5640_JD_SRC_GPIO3 = (RT5640_JD_SRC_GPIO3 << 4), |
| 46 | BYT_RT5640_JD_SRC_GPIO4 = (RT5640_JD_SRC_GPIO4 << 4), |
| 47 | }; |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 48 | |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 49 | enum { |
| 50 | BYT_RT5640_OVCD_TH_600UA = (6 << 8), |
| 51 | BYT_RT5640_OVCD_TH_1500UA = (15 << 8), |
| 52 | BYT_RT5640_OVCD_TH_2000UA = (20 << 8), |
| 53 | }; |
| 54 | |
| 55 | enum { |
| 56 | BYT_RT5640_OVCD_SF_0P5 = (RT5640_OVCD_SF_0P5 << 13), |
| 57 | BYT_RT5640_OVCD_SF_0P75 = (RT5640_OVCD_SF_0P75 << 13), |
| 58 | BYT_RT5640_OVCD_SF_1P0 = (RT5640_OVCD_SF_1P0 << 13), |
| 59 | BYT_RT5640_OVCD_SF_1P5 = (RT5640_OVCD_SF_1P5 << 13), |
| 60 | }; |
| 61 | |
| 62 | #define BYT_RT5640_MAP(quirk) ((quirk) & GENMASK(3, 0)) |
| 63 | #define BYT_RT5640_JDSRC(quirk) (((quirk) & GENMASK(7, 4)) >> 4) |
| 64 | #define BYT_RT5640_OVCD_TH(quirk) (((quirk) & GENMASK(12, 8)) >> 8) |
| 65 | #define BYT_RT5640_OVCD_SF(quirk) (((quirk) & GENMASK(14, 13)) >> 13) |
| 66 | #define BYT_RT5640_JD_NOT_INV BIT(16) |
| 67 | #define BYT_RT5640_MONO_SPEAKER BIT(17) |
| 68 | #define BYT_RT5640_DIFF_MIC BIT(18) /* default is single-ended */ |
| 69 | #define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */ |
| 70 | #define BYT_RT5640_SSP0_AIF1 BIT(20) |
| 71 | #define BYT_RT5640_SSP0_AIF2 BIT(21) |
| 72 | #define BYT_RT5640_MCLK_EN BIT(22) |
| 73 | #define BYT_RT5640_MCLK_25MHZ BIT(23) |
| 74 | |
Hans de Goede | 96a388fe | 2018-05-13 09:24:30 +0200 | [diff] [blame] | 75 | #define BYTCR_INPUT_DEFAULTS \ |
| 76 | (BYT_RT5640_IN3_MAP | \ |
Hans de Goede | 56ff440 | 2018-05-13 09:24:31 +0200 | [diff] [blame] | 77 | BYT_RT5640_JD_SRC_JD1_IN4P | \ |
| 78 | BYT_RT5640_OVCD_TH_2000UA | \ |
| 79 | BYT_RT5640_OVCD_SF_0P75 | \ |
Hans de Goede | 96a388fe | 2018-05-13 09:24:30 +0200 | [diff] [blame] | 80 | BYT_RT5640_DIFF_MIC) |
| 81 | |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 82 | /* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */ |
| 83 | #define MAX_NO_PROPS 6 |
Hans de Goede | 6a7c05e | 2018-05-08 17:35:54 +0200 | [diff] [blame] | 84 | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 85 | struct byt_rt5640_private { |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 86 | struct snd_soc_jack jack; |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 87 | struct clk *mclk; |
| 88 | }; |
Pierre-Louis Bossart | cb67d76 | 2017-04-24 16:34:33 -0500 | [diff] [blame] | 89 | static bool is_bytcr; |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 90 | |
Pierre-Louis Bossart | bf46241 | 2016-11-12 18:07:46 -0600 | [diff] [blame] | 91 | static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN; |
Pierre-Louis Bossart | 2fb2a19 | 2019-04-19 15:12:17 -0500 | [diff] [blame] | 92 | static int quirk_override = -1; |
| 93 | module_param_named(quirk, quirk_override, int, 0444); |
Takashi Iwai | 9f2cf73 | 2017-04-23 09:22:56 +0200 | [diff] [blame] | 94 | MODULE_PARM_DESC(quirk, "Board-specific quirk override"); |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 95 | |
Pierre-Louis Bossart | d7e60d5 | 2016-08-12 16:28:00 -0500 | [diff] [blame] | 96 | static void log_quirks(struct device *dev) |
| 97 | { |
Pierre-Louis Bossart | cb67d76 | 2017-04-24 16:34:33 -0500 | [diff] [blame] | 98 | int map; |
Pierre-Louis Bossart | cb67d76 | 2017-04-24 16:34:33 -0500 | [diff] [blame] | 99 | bool has_mclk = false; |
| 100 | bool has_ssp0 = false; |
| 101 | bool has_ssp0_aif1 = false; |
| 102 | bool has_ssp0_aif2 = false; |
| 103 | bool has_ssp2_aif2 = false; |
| 104 | |
| 105 | map = BYT_RT5640_MAP(byt_rt5640_quirk); |
| 106 | switch (map) { |
| 107 | case BYT_RT5640_DMIC1_MAP: |
| 108 | dev_info(dev, "quirk DMIC1_MAP enabled\n"); |
Pierre-Louis Bossart | cb67d76 | 2017-04-24 16:34:33 -0500 | [diff] [blame] | 109 | break; |
| 110 | case BYT_RT5640_DMIC2_MAP: |
| 111 | dev_info(dev, "quirk DMIC2_MAP enabled\n"); |
Pierre-Louis Bossart | cb67d76 | 2017-04-24 16:34:33 -0500 | [diff] [blame] | 112 | break; |
| 113 | case BYT_RT5640_IN1_MAP: |
| 114 | dev_info(dev, "quirk IN1_MAP enabled\n"); |
| 115 | break; |
| 116 | case BYT_RT5640_IN3_MAP: |
| 117 | dev_info(dev, "quirk IN3_MAP enabled\n"); |
| 118 | break; |
| 119 | default: |
| 120 | dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map); |
| 121 | break; |
| 122 | } |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 123 | if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) { |
| 124 | dev_info(dev, "quirk realtek,jack-detect-source %ld\n", |
| 125 | BYT_RT5640_JDSRC(byt_rt5640_quirk)); |
| 126 | dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n", |
| 127 | BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100); |
| 128 | dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n", |
| 129 | BYT_RT5640_OVCD_SF(byt_rt5640_quirk)); |
| 130 | } |
| 131 | if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV) |
| 132 | dev_info(dev, "quirk JD_NOT_INV enabled\n"); |
Pierre-Louis Bossart | d7e60d5 | 2016-08-12 16:28:00 -0500 | [diff] [blame] | 133 | if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) |
Pierre-Louis Bossart | cb67d76 | 2017-04-24 16:34:33 -0500 | [diff] [blame] | 134 | dev_info(dev, "quirk MONO_SPEAKER enabled\n"); |
Hans de Goede | a3ad291 | 2018-05-13 09:24:26 +0200 | [diff] [blame] | 135 | if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC) |
| 136 | dev_info(dev, "quirk DIFF_MIC enabled\n"); |
Pierre-Louis Bossart | cb67d76 | 2017-04-24 16:34:33 -0500 | [diff] [blame] | 137 | if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) { |
| 138 | dev_info(dev, "quirk SSP0_AIF1 enabled\n"); |
| 139 | has_ssp0 = true; |
| 140 | has_ssp0_aif1 = true; |
| 141 | } |
| 142 | if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) { |
| 143 | dev_info(dev, "quirk SSP0_AIF2 enabled\n"); |
| 144 | has_ssp0 = true; |
| 145 | has_ssp0_aif2 = true; |
| 146 | } |
| 147 | if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) { |
| 148 | dev_info(dev, "quirk SSP2_AIF2 enabled\n"); |
| 149 | has_ssp2_aif2 = true; |
| 150 | } |
| 151 | if (is_bytcr && !has_ssp0) |
| 152 | dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2 on bytcr\n"); |
| 153 | if (has_ssp0_aif1 && has_ssp0_aif2) |
| 154 | dev_err(dev, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n"); |
| 155 | if (has_ssp0 && has_ssp2_aif2) |
| 156 | dev_err(dev, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n"); |
| 157 | |
| 158 | if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) { |
| 159 | dev_info(dev, "quirk MCLK_EN enabled\n"); |
| 160 | has_mclk = true; |
| 161 | } |
| 162 | if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) { |
| 163 | if (has_mclk) |
| 164 | dev_info(dev, "quirk MCLK_25MHZ enabled\n"); |
| 165 | else |
| 166 | dev_err(dev, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n"); |
| 167 | } |
Pierre-Louis Bossart | d7e60d5 | 2016-08-12 16:28:00 -0500 | [diff] [blame] | 168 | } |
| 169 | |
Hans de Goede | bcd9a32 | 2018-05-08 17:35:53 +0200 | [diff] [blame] | 170 | static int byt_rt5640_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai, |
| 171 | int rate) |
| 172 | { |
| 173 | int ret; |
| 174 | |
| 175 | /* Configure the PLL before selecting it */ |
| 176 | if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) { |
| 177 | /* use bitclock as PLL input */ |
| 178 | if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) || |
| 179 | (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) { |
| 180 | /* 2x16 bit slots on SSP0 */ |
| 181 | ret = snd_soc_dai_set_pll(codec_dai, 0, |
| 182 | RT5640_PLL1_S_BCLK1, |
| 183 | rate * 32, rate * 512); |
| 184 | } else { |
| 185 | /* 2x15 bit slots on SSP2 */ |
| 186 | ret = snd_soc_dai_set_pll(codec_dai, 0, |
| 187 | RT5640_PLL1_S_BCLK1, |
| 188 | rate * 50, rate * 512); |
| 189 | } |
| 190 | } else { |
| 191 | if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) { |
| 192 | ret = snd_soc_dai_set_pll(codec_dai, 0, |
| 193 | RT5640_PLL1_S_MCLK, |
| 194 | 25000000, rate * 512); |
| 195 | } else { |
| 196 | ret = snd_soc_dai_set_pll(codec_dai, 0, |
| 197 | RT5640_PLL1_S_MCLK, |
| 198 | 19200000, rate * 512); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | if (ret < 0) { |
Hans de Goede | a3a956a | 2018-05-11 11:52:16 +0200 | [diff] [blame] | 203 | dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret); |
Hans de Goede | bcd9a32 | 2018-05-08 17:35:53 +0200 | [diff] [blame] | 204 | return ret; |
| 205 | } |
| 206 | |
| 207 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1, |
| 208 | rate * 512, SND_SOC_CLOCK_IN); |
| 209 | if (ret < 0) { |
Hans de Goede | a3a956a | 2018-05-11 11:52:16 +0200 | [diff] [blame] | 210 | dev_err(codec_dai->component->dev, "can't set clock %d\n", ret); |
Hans de Goede | bcd9a32 | 2018-05-08 17:35:53 +0200 | [diff] [blame] | 211 | return ret; |
| 212 | } |
| 213 | |
| 214 | return 0; |
| 215 | } |
Pierre-Louis Bossart | d7e60d5 | 2016-08-12 16:28:00 -0500 | [diff] [blame] | 216 | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 217 | #define BYT_CODEC_DAI1 "rt5640-aif1" |
| 218 | #define BYT_CODEC_DAI2 "rt5640-aif2" |
| 219 | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 220 | static int platform_clock_control(struct snd_soc_dapm_widget *w, |
| 221 | struct snd_kcontrol *k, int event) |
| 222 | { |
| 223 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 224 | struct snd_soc_card *card = dapm->card; |
| 225 | struct snd_soc_dai *codec_dai; |
| 226 | struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card); |
| 227 | int ret; |
| 228 | |
Pierre-Louis Bossart | dfb6ec7 | 2017-10-12 18:38:03 -0500 | [diff] [blame] | 229 | codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1); |
| 230 | if (!codec_dai) |
| 231 | codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2); |
| 232 | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 233 | if (!codec_dai) { |
| 234 | dev_err(card->dev, |
| 235 | "Codec dai not found; Unable to set platform clock\n"); |
| 236 | return -EIO; |
| 237 | } |
| 238 | |
| 239 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 240 | if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) { |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 241 | ret = clk_prepare_enable(priv->mclk); |
| 242 | if (ret < 0) { |
| 243 | dev_err(card->dev, |
Pierre-Louis Bossart | cb67d76 | 2017-04-24 16:34:33 -0500 | [diff] [blame] | 244 | "could not configure MCLK state\n"); |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 245 | return ret; |
| 246 | } |
| 247 | } |
Hans de Goede | bcd9a32 | 2018-05-08 17:35:53 +0200 | [diff] [blame] | 248 | ret = byt_rt5640_prepare_and_enable_pll1(codec_dai, 48000); |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 249 | } else { |
| 250 | /* |
| 251 | * Set codec clock source to internal clock before |
| 252 | * turning off the platform clock. Codec needs clock |
| 253 | * for Jack detection and button press |
| 254 | */ |
| 255 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK, |
Pierre-Louis Bossart | 60448b0 | 2017-01-04 15:44:52 -0600 | [diff] [blame] | 256 | 48000 * 512, |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 257 | SND_SOC_CLOCK_IN); |
| 258 | if (!ret) { |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 259 | if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 260 | clk_disable_unprepare(priv->mclk); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | if (ret < 0) { |
| 265 | dev_err(card->dev, "can't set codec sysclk: %d\n", ret); |
| 266 | return ret; |
| 267 | } |
| 268 | |
| 269 | return 0; |
| 270 | } |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 271 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 272 | static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 273 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 274 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
Pierre-Louis Bossart | e2be1da | 2015-12-17 20:35:40 -0600 | [diff] [blame] | 275 | SND_SOC_DAPM_MIC("Internal Mic", NULL), |
| 276 | SND_SOC_DAPM_SPK("Speaker", NULL), |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 277 | SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, |
| 278 | platform_clock_control, SND_SOC_DAPM_PRE_PMU | |
| 279 | SND_SOC_DAPM_POST_PMD), |
| 280 | |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 281 | }; |
| 282 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 283 | static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = { |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 284 | {"Headphone", NULL, "Platform Clock"}, |
| 285 | {"Headset Mic", NULL, "Platform Clock"}, |
| 286 | {"Internal Mic", NULL, "Platform Clock"}, |
| 287 | {"Speaker", NULL, "Platform Clock"}, |
| 288 | |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 289 | {"Headset Mic", NULL, "MICBIAS1"}, |
Pierre-Louis Bossart | e2be1da | 2015-12-17 20:35:40 -0600 | [diff] [blame] | 290 | {"IN2P", NULL, "Headset Mic"}, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 291 | {"Headphone", NULL, "HPOL"}, |
| 292 | {"Headphone", NULL, "HPOR"}, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 293 | }; |
| 294 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 295 | static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = { |
| 296 | {"DMIC1", NULL, "Internal Mic"}, |
| 297 | }; |
| 298 | |
| 299 | static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = { |
| 300 | {"DMIC2", NULL, "Internal Mic"}, |
| 301 | }; |
| 302 | |
| 303 | static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = { |
| 304 | {"Internal Mic", NULL, "MICBIAS1"}, |
| 305 | {"IN1P", NULL, "Internal Mic"}, |
| 306 | }; |
| 307 | |
Pierre-Louis Bossart | 59e8b65 | 2016-08-12 16:27:54 -0500 | [diff] [blame] | 308 | static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = { |
| 309 | {"Internal Mic", NULL, "MICBIAS1"}, |
| 310 | {"IN3P", NULL, "Internal Mic"}, |
| 311 | }; |
| 312 | |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame] | 313 | static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = { |
| 314 | {"ssp2 Tx", NULL, "codec_out0"}, |
| 315 | {"ssp2 Tx", NULL, "codec_out1"}, |
| 316 | {"codec_in0", NULL, "ssp2 Rx"}, |
| 317 | {"codec_in1", NULL, "ssp2 Rx"}, |
| 318 | |
| 319 | {"AIF1 Playback", NULL, "ssp2 Tx"}, |
| 320 | {"ssp2 Rx", NULL, "AIF1 Capture"}, |
| 321 | }; |
| 322 | |
| 323 | static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = { |
| 324 | {"ssp2 Tx", NULL, "codec_out0"}, |
| 325 | {"ssp2 Tx", NULL, "codec_out1"}, |
| 326 | {"codec_in0", NULL, "ssp2 Rx"}, |
| 327 | {"codec_in1", NULL, "ssp2 Rx"}, |
| 328 | |
| 329 | {"AIF2 Playback", NULL, "ssp2 Tx"}, |
| 330 | {"ssp2 Rx", NULL, "AIF2 Capture"}, |
| 331 | }; |
| 332 | |
Pierre-Louis Bossart | f47088d | 2016-08-12 16:27:51 -0500 | [diff] [blame] | 333 | static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = { |
| 334 | {"ssp0 Tx", NULL, "modem_out"}, |
| 335 | {"modem_in", NULL, "ssp0 Rx"}, |
| 336 | |
| 337 | {"AIF1 Playback", NULL, "ssp0 Tx"}, |
| 338 | {"ssp0 Rx", NULL, "AIF1 Capture"}, |
| 339 | }; |
| 340 | |
| 341 | static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = { |
| 342 | {"ssp0 Tx", NULL, "modem_out"}, |
| 343 | {"modem_in", NULL, "ssp0 Rx"}, |
| 344 | |
| 345 | {"AIF2 Playback", NULL, "ssp0 Tx"}, |
| 346 | {"ssp0 Rx", NULL, "AIF2 Capture"}, |
| 347 | }; |
| 348 | |
Pierre-Louis Bossart | 68817cd | 2016-08-12 16:27:45 -0500 | [diff] [blame] | 349 | static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = { |
| 350 | {"Speaker", NULL, "SPOLP"}, |
| 351 | {"Speaker", NULL, "SPOLN"}, |
| 352 | {"Speaker", NULL, "SPORP"}, |
| 353 | {"Speaker", NULL, "SPORN"}, |
| 354 | }; |
| 355 | |
| 356 | static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = { |
| 357 | {"Speaker", NULL, "SPOLP"}, |
| 358 | {"Speaker", NULL, "SPOLN"}, |
| 359 | }; |
| 360 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 361 | static const struct snd_kcontrol_new byt_rt5640_controls[] = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 362 | SOC_DAPM_PIN_SWITCH("Headphone"), |
| 363 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
Pierre-Louis Bossart | e2be1da | 2015-12-17 20:35:40 -0600 | [diff] [blame] | 364 | SOC_DAPM_PIN_SWITCH("Internal Mic"), |
| 365 | SOC_DAPM_PIN_SWITCH("Speaker"), |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 366 | }; |
| 367 | |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 368 | static struct snd_soc_jack_pin rt5640_pins[] = { |
| 369 | { |
| 370 | .pin = "Headphone", |
| 371 | .mask = SND_JACK_HEADPHONE, |
| 372 | }, |
| 373 | { |
| 374 | .pin = "Headset Mic", |
| 375 | .mask = SND_JACK_MICROPHONE, |
| 376 | }, |
| 377 | }; |
| 378 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 379 | static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 380 | struct snd_pcm_hw_params *params) |
| 381 | { |
Kuninori Morimoto | 2207b93 | 2020-07-27 10:08:29 +0900 | [diff] [blame] | 382 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 0d1571c | 2020-03-23 14:19:05 +0900 | [diff] [blame] | 383 | struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 384 | |
Hans de Goede | bcd9a32 | 2018-05-08 17:35:53 +0200 | [diff] [blame] | 385 | return byt_rt5640_prepare_and_enable_pll1(dai, params_rate(params)); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 386 | } |
| 387 | |
Hans de Goede | 3c0d011 | 2018-05-13 09:24:32 +0200 | [diff] [blame] | 388 | /* Please keep this list alphabetically sorted */ |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 389 | static const struct dmi_system_id byt_rt5640_quirk_table[] = { |
Hans de Goede | ec8e841 | 2018-05-13 09:24:34 +0200 | [diff] [blame] | 390 | { /* Acer Iconia Tab 8 W1-810 */ |
| 391 | .matches = { |
| 392 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 393 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"), |
| 394 | }, |
| 395 | .driver_data = (void *)(BYT_RT5640_DMIC1_MAP | |
| 396 | BYT_RT5640_JD_SRC_JD1_IN4P | |
Hans de Goede | f12a0a3 | 2018-06-03 15:42:32 +0200 | [diff] [blame] | 397 | BYT_RT5640_OVCD_TH_1500UA | |
Hans de Goede | ec8e841 | 2018-05-13 09:24:34 +0200 | [diff] [blame] | 398 | BYT_RT5640_OVCD_SF_0P75 | |
| 399 | BYT_RT5640_SSP0_AIF1 | |
| 400 | BYT_RT5640_MCLK_EN), |
| 401 | }, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 402 | { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 403 | .matches = { |
Hans de Goede | 3c0d011 | 2018-05-13 09:24:32 +0200 | [diff] [blame] | 404 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 405 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"), |
| 406 | }, |
Hans de Goede | 0bb8877 | 2019-11-19 15:51:38 +0100 | [diff] [blame] | 407 | .driver_data = (void *)(BYT_RT5640_DMIC1_MAP | |
| 408 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 409 | BYT_RT5640_OVCD_TH_2000UA | |
| 410 | BYT_RT5640_OVCD_SF_0P75 | |
| 411 | BYT_RT5640_SSP0_AIF1 | |
| 412 | BYT_RT5640_MCLK_EN), |
Hans de Goede | 3c0d011 | 2018-05-13 09:24:32 +0200 | [diff] [blame] | 413 | }, |
| 414 | { |
Hans de Goede | 3c0d011 | 2018-05-13 09:24:32 +0200 | [diff] [blame] | 415 | .matches = { |
Hans de Goede | bcf441a | 2018-05-28 22:26:49 +0200 | [diff] [blame] | 416 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"), |
| 417 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 80 Cesium"), |
| 418 | }, |
| 419 | .driver_data = (void *)(BYTCR_INPUT_DEFAULTS | |
| 420 | BYT_RT5640_MONO_SPEAKER | |
| 421 | BYT_RT5640_SSP0_AIF1 | |
| 422 | BYT_RT5640_MCLK_EN), |
| 423 | }, |
| 424 | { |
| 425 | .matches = { |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 426 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), |
Stephan Gerhold | 51a13e4 | 2019-01-02 20:39:08 +0100 | [diff] [blame] | 427 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"), |
| 428 | }, |
| 429 | .driver_data = (void *)(BYT_RT5640_IN1_MAP | |
| 430 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 431 | BYT_RT5640_OVCD_TH_2000UA | |
| 432 | BYT_RT5640_OVCD_SF_0P75 | |
| 433 | BYT_RT5640_SSP0_AIF1 | |
| 434 | BYT_RT5640_MCLK_EN), |
| 435 | }, |
| 436 | { |
| 437 | .matches = { |
| 438 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 439 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"), |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 440 | }, |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 441 | .driver_data = (void *)(BYT_RT5640_IN1_MAP | |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 442 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 443 | BYT_RT5640_OVCD_TH_2000UA | |
| 444 | BYT_RT5640_OVCD_SF_0P75 | |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 445 | BYT_RT5640_MCLK_EN), |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 446 | }, |
| 447 | { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 448 | .matches = { |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 449 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), |
| 450 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"), |
| 451 | }, |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 452 | .driver_data = (void *)(BYT_RT5640_IN1_MAP | |
| 453 | BYT_RT5640_MONO_SPEAKER | |
| 454 | BYT_RT5640_DIFF_MIC | |
| 455 | BYT_RT5640_SSP0_AIF2 | |
| 456 | BYT_RT5640_MCLK_EN), |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 457 | }, |
Hans de Goede | ec8e841 | 2018-05-13 09:24:34 +0200 | [diff] [blame] | 458 | { /* Chuwi Vi8 (CWI506) */ |
| 459 | .matches = { |
| 460 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"), |
| 461 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "i86"), |
| 462 | /* The above are too generic, also match BIOS info */ |
| 463 | DMI_MATCH(DMI_BIOS_VERSION, "CHUWI.D86JLBNR"), |
| 464 | }, |
| 465 | .driver_data = (void *)(BYTCR_INPUT_DEFAULTS | |
| 466 | BYT_RT5640_MONO_SPEAKER | |
| 467 | BYT_RT5640_SSP0_AIF1 | |
| 468 | BYT_RT5640_MCLK_EN), |
| 469 | }, |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 470 | { |
Hans de Goede | d5a1826 | 2018-06-08 10:19:25 +0200 | [diff] [blame] | 471 | /* Chuwi Vi10 (CWI505) */ |
| 472 | .matches = { |
| 473 | DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"), |
| 474 | DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"), |
| 475 | DMI_MATCH(DMI_SYS_VENDOR, "ilife"), |
| 476 | DMI_MATCH(DMI_PRODUCT_NAME, "S165"), |
| 477 | }, |
| 478 | .driver_data = (void *)(BYT_RT5640_IN1_MAP | |
| 479 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 480 | BYT_RT5640_OVCD_TH_2000UA | |
| 481 | BYT_RT5640_OVCD_SF_0P75 | |
| 482 | BYT_RT5640_DIFF_MIC | |
| 483 | BYT_RT5640_SSP0_AIF1 | |
| 484 | BYT_RT5640_MCLK_EN), |
| 485 | }, |
| 486 | { |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 487 | .matches = { |
Hans de Goede | 3c0d011 | 2018-05-13 09:24:32 +0200 | [diff] [blame] | 488 | DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"), |
| 489 | DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"), |
| 490 | }, |
| 491 | .driver_data = (void *)(BYT_RT5640_DMIC1_MAP), |
| 492 | }, |
Hans de Goede | 9ee6f8a | 2018-07-01 11:30:23 +0200 | [diff] [blame] | 493 | { /* Connect Tablet 9 */ |
| 494 | .matches = { |
| 495 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Connect"), |
| 496 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Tablet 9"), |
| 497 | }, |
| 498 | .driver_data = (void *)(BYTCR_INPUT_DEFAULTS | |
| 499 | BYT_RT5640_MONO_SPEAKER | |
| 500 | BYT_RT5640_SSP0_AIF1 | |
| 501 | BYT_RT5640_MCLK_EN), |
| 502 | }, |
Hans de Goede | 3c0d011 | 2018-05-13 09:24:32 +0200 | [diff] [blame] | 503 | { |
Hans de Goede | 3c0d011 | 2018-05-13 09:24:32 +0200 | [diff] [blame] | 504 | .matches = { |
Hans de Goede | 6748fb7 | 2018-05-13 09:24:27 +0200 | [diff] [blame] | 505 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 506 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"), |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 507 | }, |
Hans de Goede | 6748fb7 | 2018-05-13 09:24:27 +0200 | [diff] [blame] | 508 | .driver_data = (void *)(BYT_RT5640_DMIC1_MAP | |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 509 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 510 | BYT_RT5640_OVCD_TH_2000UA | |
| 511 | BYT_RT5640_OVCD_SF_0P75 | |
Hans de Goede | 6748fb7 | 2018-05-13 09:24:27 +0200 | [diff] [blame] | 512 | BYT_RT5640_MONO_SPEAKER | |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 513 | BYT_RT5640_MCLK_EN), |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 514 | }, |
Jorge Fernandez Monteagudo | 55fc205 | 2016-01-04 17:20:30 -0600 | [diff] [blame] | 515 | { |
Jorge Fernandez Monteagudo | 55fc205 | 2016-01-04 17:20:30 -0600 | [diff] [blame] | 516 | .matches = { |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 517 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), |
| 518 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"), |
Jorge Fernandez Monteagudo | 55fc205 | 2016-01-04 17:20:30 -0600 | [diff] [blame] | 519 | }, |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 520 | .driver_data = (void *)(BYT_RT5640_IN1_MAP | |
| 521 | BYT_RT5640_MCLK_EN), |
Jorge Fernandez Monteagudo | 55fc205 | 2016-01-04 17:20:30 -0600 | [diff] [blame] | 522 | }, |
Hans de Goede | ec8e841 | 2018-05-13 09:24:34 +0200 | [diff] [blame] | 523 | { /* HP Pavilion x2 10-n000nd */ |
| 524 | .matches = { |
| 525 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), |
| 526 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Pavilion x2 Detachable"), |
| 527 | }, |
| 528 | .driver_data = (void *)(BYT_RT5640_DMIC1_MAP | |
| 529 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 530 | BYT_RT5640_OVCD_TH_1500UA | |
| 531 | BYT_RT5640_OVCD_SF_0P75 | |
| 532 | BYT_RT5640_SSP0_AIF1 | |
| 533 | BYT_RT5640_MCLK_EN), |
| 534 | }, |
| 535 | { /* HP Stream 7 */ |
| 536 | .matches = { |
| 537 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), |
| 538 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Stream 7 Tablet"), |
| 539 | }, |
| 540 | .driver_data = (void *)(BYTCR_INPUT_DEFAULTS | |
| 541 | BYT_RT5640_MONO_SPEAKER | |
| 542 | BYT_RT5640_JD_NOT_INV | |
| 543 | BYT_RT5640_SSP0_AIF1 | |
| 544 | BYT_RT5640_MCLK_EN), |
| 545 | }, |
| 546 | { /* I.T.Works TW891 */ |
| 547 | .matches = { |
| 548 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."), |
| 549 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"), |
| 550 | DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."), |
| 551 | DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"), |
| 552 | }, |
| 553 | .driver_data = (void *)(BYTCR_INPUT_DEFAULTS | |
| 554 | BYT_RT5640_MONO_SPEAKER | |
| 555 | BYT_RT5640_SSP0_AIF1 | |
| 556 | BYT_RT5640_MCLK_EN), |
| 557 | }, |
| 558 | { /* Lamina I8270 / T701BR.SE */ |
| 559 | .matches = { |
| 560 | DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Lamina"), |
| 561 | DMI_EXACT_MATCH(DMI_BOARD_NAME, "T701BR.SE"), |
| 562 | }, |
| 563 | .driver_data = (void *)(BYTCR_INPUT_DEFAULTS | |
| 564 | BYT_RT5640_MONO_SPEAKER | |
| 565 | BYT_RT5640_JD_NOT_INV | |
| 566 | BYT_RT5640_SSP0_AIF1 | |
| 567 | BYT_RT5640_MCLK_EN), |
| 568 | }, |
Hans de Goede | 81583af | 2018-07-07 12:22:10 +0200 | [diff] [blame] | 569 | { /* Lenovo Miix 2 8 */ |
| 570 | .matches = { |
| 571 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"), |
| 572 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "20326"), |
| 573 | DMI_EXACT_MATCH(DMI_BOARD_NAME, "Hiking"), |
| 574 | }, |
| 575 | .driver_data = (void *)(BYT_RT5640_DMIC1_MAP | |
| 576 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 577 | BYT_RT5640_OVCD_TH_2000UA | |
| 578 | BYT_RT5640_OVCD_SF_0P75 | |
| 579 | BYT_RT5640_MONO_SPEAKER | |
| 580 | BYT_RT5640_MCLK_EN), |
| 581 | }, |
Hans de Goede | 260c48b | 2018-08-12 13:42:06 +0200 | [diff] [blame] | 582 | { /* Linx Linx7 tablet */ |
| 583 | .matches = { |
| 584 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LINX"), |
| 585 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LINX7"), |
| 586 | }, |
| 587 | .driver_data = (void *)(BYTCR_INPUT_DEFAULTS | |
| 588 | BYT_RT5640_MONO_SPEAKER | |
| 589 | BYT_RT5640_JD_NOT_INV | |
| 590 | BYT_RT5640_SSP0_AIF1 | |
| 591 | BYT_RT5640_MCLK_EN), |
| 592 | }, |
Hans de Goede | 6a01371 | 2020-09-01 10:06:23 +0200 | [diff] [blame] | 593 | { /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */ |
| 594 | .matches = { |
| 595 | DMI_MATCH(DMI_SYS_VENDOR, "MPMAN"), |
| 596 | DMI_MATCH(DMI_PRODUCT_NAME, "Converter9"), |
| 597 | }, |
| 598 | .driver_data = (void *)(BYTCR_INPUT_DEFAULTS | |
| 599 | BYT_RT5640_MONO_SPEAKER | |
| 600 | BYT_RT5640_SSP0_AIF1 | |
| 601 | BYT_RT5640_MCLK_EN), |
| 602 | }, |
Hans de Goede | c8b78f2 | 2020-04-05 15:37:26 +0200 | [diff] [blame] | 603 | { |
| 604 | /* MPMAN MPWIN895CL */ |
| 605 | .matches = { |
| 606 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MPMAN"), |
| 607 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MPWIN8900CL"), |
| 608 | }, |
| 609 | .driver_data = (void *)(BYTCR_INPUT_DEFAULTS | |
| 610 | BYT_RT5640_MONO_SPEAKER | |
| 611 | BYT_RT5640_SSP0_AIF1 | |
| 612 | BYT_RT5640_MCLK_EN), |
| 613 | }, |
Hans de Goede | ec8e841 | 2018-05-13 09:24:34 +0200 | [diff] [blame] | 614 | { /* MSI S100 tablet */ |
| 615 | .matches = { |
| 616 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."), |
| 617 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "S100"), |
| 618 | }, |
| 619 | .driver_data = (void *)(BYT_RT5640_IN1_MAP | |
| 620 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 621 | BYT_RT5640_OVCD_TH_2000UA | |
| 622 | BYT_RT5640_OVCD_SF_0P75 | |
| 623 | BYT_RT5640_MONO_SPEAKER | |
| 624 | BYT_RT5640_DIFF_MIC | |
| 625 | BYT_RT5640_MCLK_EN), |
| 626 | }, |
Hans de Goede | 6cea359 | 2018-06-03 15:42:31 +0200 | [diff] [blame] | 627 | { /* Nuvison/TMax TM800W560 */ |
| 628 | .matches = { |
| 629 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TMAX"), |
| 630 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TM800W560L"), |
| 631 | }, |
| 632 | .driver_data = (void *)(BYT_RT5640_IN1_MAP | |
| 633 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 634 | BYT_RT5640_OVCD_TH_2000UA | |
| 635 | BYT_RT5640_OVCD_SF_0P75 | |
| 636 | BYT_RT5640_JD_NOT_INV | |
| 637 | BYT_RT5640_DIFF_MIC | |
| 638 | BYT_RT5640_SSP0_AIF1 | |
| 639 | BYT_RT5640_MCLK_EN), |
| 640 | }, |
Hans de Goede | 260c48b | 2018-08-12 13:42:06 +0200 | [diff] [blame] | 641 | { /* Onda v975w */ |
| 642 | .matches = { |
| 643 | DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), |
| 644 | DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"), |
| 645 | /* The above are too generic, also match BIOS info */ |
| 646 | DMI_EXACT_MATCH(DMI_BIOS_VERSION, "5.6.5"), |
| 647 | DMI_EXACT_MATCH(DMI_BIOS_DATE, "07/25/2014"), |
| 648 | }, |
| 649 | .driver_data = (void *)(BYT_RT5640_IN1_MAP | |
| 650 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 651 | BYT_RT5640_OVCD_TH_2000UA | |
| 652 | BYT_RT5640_OVCD_SF_0P75 | |
| 653 | BYT_RT5640_DIFF_MIC | |
| 654 | BYT_RT5640_MCLK_EN), |
| 655 | }, |
Hans de Goede | ec8e841 | 2018-05-13 09:24:34 +0200 | [diff] [blame] | 656 | { /* Pipo W4 */ |
| 657 | .matches = { |
| 658 | DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), |
| 659 | DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"), |
| 660 | /* The above are too generic, also match BIOS info */ |
| 661 | DMI_MATCH(DMI_BIOS_VERSION, "V8L_WIN32_CHIPHD"), |
| 662 | }, |
| 663 | .driver_data = (void *)(BYTCR_INPUT_DEFAULTS | |
| 664 | BYT_RT5640_MONO_SPEAKER | |
| 665 | BYT_RT5640_SSP0_AIF1 | |
| 666 | BYT_RT5640_MCLK_EN), |
| 667 | }, |
| 668 | { /* Point of View Mobii TAB-P800W (V2.0) */ |
| 669 | .matches = { |
| 670 | DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), |
| 671 | DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"), |
| 672 | /* The above are too generic, also match BIOS info */ |
| 673 | DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1014"), |
| 674 | DMI_EXACT_MATCH(DMI_BIOS_DATE, "10/24/2014"), |
| 675 | }, |
| 676 | .driver_data = (void *)(BYT_RT5640_IN1_MAP | |
| 677 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 678 | BYT_RT5640_OVCD_TH_2000UA | |
| 679 | BYT_RT5640_OVCD_SF_0P75 | |
| 680 | BYT_RT5640_MONO_SPEAKER | |
| 681 | BYT_RT5640_DIFF_MIC | |
| 682 | BYT_RT5640_SSP0_AIF2 | |
| 683 | BYT_RT5640_MCLK_EN), |
| 684 | }, |
| 685 | { /* Point of View Mobii TAB-P800W (V2.1) */ |
| 686 | .matches = { |
| 687 | DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), |
| 688 | DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"), |
| 689 | /* The above are too generic, also match BIOS info */ |
| 690 | DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1013"), |
| 691 | DMI_EXACT_MATCH(DMI_BIOS_DATE, "08/22/2014"), |
| 692 | }, |
| 693 | .driver_data = (void *)(BYT_RT5640_IN1_MAP | |
| 694 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 695 | BYT_RT5640_OVCD_TH_2000UA | |
| 696 | BYT_RT5640_OVCD_SF_0P75 | |
| 697 | BYT_RT5640_MONO_SPEAKER | |
| 698 | BYT_RT5640_DIFF_MIC | |
| 699 | BYT_RT5640_SSP0_AIF2 | |
| 700 | BYT_RT5640_MCLK_EN), |
| 701 | }, |
Hans de Goede | 02e5af6 | 2018-12-08 14:01:14 +0100 | [diff] [blame] | 702 | { /* Point of View Mobii TAB-P1005W-232 (V2.0) */ |
| 703 | .matches = { |
| 704 | DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "POV"), |
| 705 | DMI_EXACT_MATCH(DMI_BOARD_NAME, "I102A"), |
| 706 | }, |
| 707 | .driver_data = (void *)(BYT_RT5640_IN1_MAP | |
| 708 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 709 | BYT_RT5640_OVCD_TH_2000UA | |
| 710 | BYT_RT5640_OVCD_SF_0P75 | |
| 711 | BYT_RT5640_DIFF_MIC | |
| 712 | BYT_RT5640_SSP0_AIF1 | |
| 713 | BYT_RT5640_MCLK_EN), |
| 714 | }, |
Irina Tirdea | 0565e77 | 2016-08-12 16:27:58 -0500 | [diff] [blame] | 715 | { |
Hans de Goede | 271248f | 2018-12-08 14:01:13 +0100 | [diff] [blame] | 716 | /* Prowise PT301 */ |
| 717 | .matches = { |
| 718 | DMI_MATCH(DMI_SYS_VENDOR, "Prowise"), |
| 719 | DMI_MATCH(DMI_PRODUCT_NAME, "PT301"), |
| 720 | }, |
| 721 | .driver_data = (void *)(BYT_RT5640_IN1_MAP | |
| 722 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 723 | BYT_RT5640_OVCD_TH_2000UA | |
| 724 | BYT_RT5640_OVCD_SF_0P75 | |
| 725 | BYT_RT5640_DIFF_MIC | |
| 726 | BYT_RT5640_SSP0_AIF1 | |
| 727 | BYT_RT5640_MCLK_EN), |
| 728 | }, |
| 729 | { |
Hans de Goede | 7eccc05 | 2019-12-03 23:14:42 +0100 | [diff] [blame] | 730 | /* Teclast X89 */ |
Irina Tirdea | 0565e77 | 2016-08-12 16:27:58 -0500 | [diff] [blame] | 731 | .matches = { |
Pierre-Louis Bossart | ec1c90e | 2016-08-12 16:27:59 -0500 | [diff] [blame] | 732 | DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"), |
| 733 | DMI_MATCH(DMI_BOARD_NAME, "tPAD"), |
| 734 | }, |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 735 | .driver_data = (void *)(BYT_RT5640_IN3_MAP | |
Hans de Goede | 7eccc05 | 2019-12-03 23:14:42 +0100 | [diff] [blame] | 736 | BYT_RT5640_JD_SRC_JD1_IN4P | |
| 737 | BYT_RT5640_OVCD_TH_2000UA | |
| 738 | BYT_RT5640_OVCD_SF_1P0 | |
| 739 | BYT_RT5640_SSP0_AIF1 | |
| 740 | BYT_RT5640_MCLK_EN), |
Pierre-Louis Bossart | ec1c90e | 2016-08-12 16:27:59 -0500 | [diff] [blame] | 741 | }, |
Hans de Goede | ec8e841 | 2018-05-13 09:24:34 +0200 | [diff] [blame] | 742 | { /* Toshiba Satellite Click Mini L9W-B */ |
| 743 | .matches = { |
| 744 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
| 745 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"), |
| 746 | }, |
| 747 | .driver_data = (void *)(BYT_RT5640_DMIC1_MAP | |
| 748 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 749 | BYT_RT5640_OVCD_TH_1500UA | |
| 750 | BYT_RT5640_OVCD_SF_0P75 | |
| 751 | BYT_RT5640_SSP0_AIF1 | |
| 752 | BYT_RT5640_MCLK_EN), |
| 753 | }, |
Hans de Goede | 0e0e10f | 2020-05-18 09:24:16 +0200 | [diff] [blame] | 754 | { /* Toshiba Encore WT8-A */ |
| 755 | .matches = { |
| 756 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
| 757 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"), |
| 758 | }, |
| 759 | .driver_data = (void *)(BYT_RT5640_DMIC1_MAP | |
| 760 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 761 | BYT_RT5640_OVCD_TH_2000UA | |
| 762 | BYT_RT5640_OVCD_SF_0P75 | |
| 763 | BYT_RT5640_JD_NOT_INV | |
| 764 | BYT_RT5640_MCLK_EN), |
| 765 | }, |
Hans de Goede | 199a5e8 | 2020-06-08 22:46:33 +0200 | [diff] [blame] | 766 | { /* Toshiba Encore WT10-A */ |
| 767 | .matches = { |
| 768 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
| 769 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"), |
| 770 | }, |
| 771 | .driver_data = (void *)(BYT_RT5640_DMIC1_MAP | |
| 772 | BYT_RT5640_JD_SRC_JD1_IN4P | |
| 773 | BYT_RT5640_OVCD_TH_2000UA | |
| 774 | BYT_RT5640_OVCD_SF_0P75 | |
| 775 | BYT_RT5640_SSP0_AIF2 | |
| 776 | BYT_RT5640_MCLK_EN), |
| 777 | }, |
Hans de Goede | 3c0d011 | 2018-05-13 09:24:32 +0200 | [diff] [blame] | 778 | { /* Catch-all for generic Insyde tablets, must be last */ |
youling257 | 5718004 | 2017-01-04 15:44:53 -0600 | [diff] [blame] | 779 | .matches = { |
| 780 | DMI_MATCH(DMI_SYS_VENDOR, "Insyde"), |
| 781 | }, |
Hans de Goede | 96a388fe | 2018-05-13 09:24:30 +0200 | [diff] [blame] | 782 | .driver_data = (void *)(BYTCR_INPUT_DEFAULTS | |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 783 | BYT_RT5640_MCLK_EN | |
| 784 | BYT_RT5640_SSP0_AIF1), |
youling257 | 5718004 | 2017-01-04 15:44:53 -0600 | [diff] [blame] | 785 | |
| 786 | }, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 787 | {} |
| 788 | }; |
| 789 | |
Hans de Goede | 6a7c05e | 2018-05-08 17:35:54 +0200 | [diff] [blame] | 790 | /* |
| 791 | * Note this MUST be called before snd_soc_register_card(), so that the props |
| 792 | * are in place before the codec component driver's probe function parses them. |
| 793 | */ |
| 794 | static int byt_rt5640_add_codec_device_props(const char *i2c_dev_name) |
| 795 | { |
| 796 | struct property_entry props[MAX_NO_PROPS] = {}; |
| 797 | struct device *i2c_dev; |
| 798 | int ret, cnt = 0; |
| 799 | |
| 800 | i2c_dev = bus_find_device_by_name(&i2c_bus_type, NULL, i2c_dev_name); |
| 801 | if (!i2c_dev) |
| 802 | return -EPROBE_DEFER; |
| 803 | |
| 804 | switch (BYT_RT5640_MAP(byt_rt5640_quirk)) { |
Hans de Goede | a3ad291 | 2018-05-13 09:24:26 +0200 | [diff] [blame] | 805 | case BYT_RT5640_DMIC1_MAP: |
| 806 | props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin", |
| 807 | RT5640_DMIC1_DATA_PIN_IN1P); |
| 808 | break; |
| 809 | case BYT_RT5640_DMIC2_MAP: |
| 810 | props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin", |
| 811 | RT5640_DMIC2_DATA_PIN_IN1N); |
| 812 | break; |
Hans de Goede | 6a7c05e | 2018-05-08 17:35:54 +0200 | [diff] [blame] | 813 | case BYT_RT5640_IN1_MAP: |
| 814 | if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC) |
| 815 | props[cnt++] = |
| 816 | PROPERTY_ENTRY_BOOL("realtek,in1-differential"); |
| 817 | break; |
| 818 | case BYT_RT5640_IN3_MAP: |
| 819 | if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC) |
| 820 | props[cnt++] = |
| 821 | PROPERTY_ENTRY_BOOL("realtek,in3-differential"); |
| 822 | break; |
| 823 | } |
| 824 | |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 825 | if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) { |
| 826 | props[cnt++] = PROPERTY_ENTRY_U32( |
| 827 | "realtek,jack-detect-source", |
| 828 | BYT_RT5640_JDSRC(byt_rt5640_quirk)); |
| 829 | |
| 830 | props[cnt++] = PROPERTY_ENTRY_U32( |
| 831 | "realtek,over-current-threshold-microamp", |
| 832 | BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100); |
| 833 | |
| 834 | props[cnt++] = PROPERTY_ENTRY_U32( |
| 835 | "realtek,over-current-scale-factor", |
| 836 | BYT_RT5640_OVCD_SF(byt_rt5640_quirk)); |
| 837 | } |
| 838 | |
| 839 | if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV) |
| 840 | props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted"); |
| 841 | |
Hans de Goede | 6a7c05e | 2018-05-08 17:35:54 +0200 | [diff] [blame] | 842 | ret = device_add_properties(i2c_dev, props); |
| 843 | put_device(i2c_dev); |
| 844 | |
| 845 | return ret; |
| 846 | } |
| 847 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 848 | static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime) |
| 849 | { |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 850 | struct snd_soc_card *card = runtime->card; |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 851 | struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card); |
Kuninori Morimoto | 0d1571c | 2020-03-23 14:19:05 +0900 | [diff] [blame] | 852 | struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component; |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 853 | const struct snd_soc_dapm_route *custom_map; |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 854 | int num_routes; |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 855 | int ret; |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 856 | |
| 857 | card->dapm.idle_bias_off = true; |
| 858 | |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 859 | /* Start with RC clk for jack-detect (we disable MCLK below) */ |
| 860 | if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) |
| 861 | snd_soc_component_update_bits(component, RT5640_GLB_CLK, |
| 862 | RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_RCCLK); |
| 863 | |
Kuninori Morimoto | d5a41b5 | 2018-01-29 03:42:46 +0000 | [diff] [blame] | 864 | rt5640_sel_asrc_clk_src(component, |
Pierre-Louis Bossart | 0ec66e2d | 2016-01-04 17:20:27 -0600 | [diff] [blame] | 865 | RT5640_DA_STEREO_FILTER | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 866 | RT5640_DA_MONO_L_FILTER | |
| 867 | RT5640_DA_MONO_R_FILTER | |
| 868 | RT5640_AD_STEREO_FILTER | |
| 869 | RT5640_AD_MONO_L_FILTER | |
| 870 | RT5640_AD_MONO_R_FILTER, |
Pierre-Louis Bossart | 0ec66e2d | 2016-01-04 17:20:27 -0600 | [diff] [blame] | 871 | RT5640_CLK_SEL_ASRC); |
| 872 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 873 | ret = snd_soc_add_card_controls(card, byt_rt5640_controls, |
| 874 | ARRAY_SIZE(byt_rt5640_controls)); |
| 875 | if (ret) { |
| 876 | dev_err(card->dev, "unable to add card controls\n"); |
| 877 | return ret; |
| 878 | } |
| 879 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 880 | switch (BYT_RT5640_MAP(byt_rt5640_quirk)) { |
| 881 | case BYT_RT5640_IN1_MAP: |
| 882 | custom_map = byt_rt5640_intmic_in1_map; |
| 883 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map); |
| 884 | break; |
Pierre-Louis Bossart | 59e8b65 | 2016-08-12 16:27:54 -0500 | [diff] [blame] | 885 | case BYT_RT5640_IN3_MAP: |
| 886 | custom_map = byt_rt5640_intmic_in3_map; |
| 887 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map); |
| 888 | break; |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 889 | case BYT_RT5640_DMIC2_MAP: |
| 890 | custom_map = byt_rt5640_intmic_dmic2_map; |
| 891 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map); |
| 892 | break; |
| 893 | default: |
| 894 | custom_map = byt_rt5640_intmic_dmic1_map; |
| 895 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map); |
| 896 | } |
| 897 | |
| 898 | ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes); |
| 899 | if (ret) |
| 900 | return ret; |
| 901 | |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame] | 902 | if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) { |
| 903 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 904 | byt_rt5640_ssp2_aif2_map, |
| 905 | ARRAY_SIZE(byt_rt5640_ssp2_aif2_map)); |
Pierre-Louis Bossart | f47088d | 2016-08-12 16:27:51 -0500 | [diff] [blame] | 906 | } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) { |
| 907 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 908 | byt_rt5640_ssp0_aif1_map, |
| 909 | ARRAY_SIZE(byt_rt5640_ssp0_aif1_map)); |
| 910 | } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) { |
| 911 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 912 | byt_rt5640_ssp0_aif2_map, |
| 913 | ARRAY_SIZE(byt_rt5640_ssp0_aif2_map)); |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame] | 914 | } else { |
| 915 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 916 | byt_rt5640_ssp2_aif1_map, |
| 917 | ARRAY_SIZE(byt_rt5640_ssp2_aif1_map)); |
| 918 | } |
| 919 | if (ret) |
| 920 | return ret; |
| 921 | |
Pierre-Louis Bossart | 68817cd | 2016-08-12 16:27:45 -0500 | [diff] [blame] | 922 | if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) { |
| 923 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 924 | byt_rt5640_mono_spk_map, |
| 925 | ARRAY_SIZE(byt_rt5640_mono_spk_map)); |
| 926 | } else { |
| 927 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 928 | byt_rt5640_stereo_spk_map, |
| 929 | ARRAY_SIZE(byt_rt5640_stereo_spk_map)); |
| 930 | } |
| 931 | if (ret) |
| 932 | return ret; |
| 933 | |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 934 | if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) { |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 935 | /* |
| 936 | * The firmware might enable the clock at |
| 937 | * boot (this information may or may not |
| 938 | * be reflected in the enable clock register). |
| 939 | * To change the rate we must disable the clock |
| 940 | * first to cover these cases. Due to common |
| 941 | * clock framework restrictions that do not allow |
| 942 | * to disable a clock that has not been enabled, |
| 943 | * we need to enable the clock first. |
| 944 | */ |
| 945 | ret = clk_prepare_enable(priv->mclk); |
| 946 | if (!ret) |
| 947 | clk_disable_unprepare(priv->mclk); |
| 948 | |
| 949 | if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) |
| 950 | ret = clk_set_rate(priv->mclk, 25000000); |
| 951 | else |
| 952 | ret = clk_set_rate(priv->mclk, 19200000); |
| 953 | |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 954 | if (ret) { |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 955 | dev_err(card->dev, "unable to set MCLK rate\n"); |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 956 | return ret; |
| 957 | } |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 958 | } |
| 959 | |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 960 | if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) { |
| 961 | ret = snd_soc_card_jack_new(card, "Headset", |
| 962 | SND_JACK_HEADSET | SND_JACK_BTN_0, |
| 963 | &priv->jack, rt5640_pins, |
| 964 | ARRAY_SIZE(rt5640_pins)); |
| 965 | if (ret) { |
| 966 | dev_err(card->dev, "Jack creation failed %d\n", ret); |
| 967 | return ret; |
| 968 | } |
| 969 | snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0, |
| 970 | KEY_PLAYPAUSE); |
| 971 | snd_soc_component_set_jack(component, &priv->jack, NULL); |
| 972 | } |
| 973 | |
| 974 | return 0; |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 975 | } |
| 976 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 977 | static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 978 | struct snd_pcm_hw_params *params) |
| 979 | { |
| 980 | struct snd_interval *rate = hw_param_interval(params, |
| 981 | SNDRV_PCM_HW_PARAM_RATE); |
| 982 | struct snd_interval *channels = hw_param_interval(params, |
| 983 | SNDRV_PCM_HW_PARAM_CHANNELS); |
Erik Bussing | 332719b | 2020-01-15 17:46:16 +0100 | [diff] [blame] | 984 | int ret, bits; |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 985 | |
Pierre-Louis Bossart | 038a50e | 2016-08-12 16:27:52 -0500 | [diff] [blame] | 986 | /* The DSP will covert the FE rate to 48k, stereo */ |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 987 | rate->min = rate->max = 48000; |
| 988 | channels->min = channels->max = 2; |
| 989 | |
Pierre-Louis Bossart | 038a50e | 2016-08-12 16:27:52 -0500 | [diff] [blame] | 990 | if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) || |
Erik Bussing | 332719b | 2020-01-15 17:46:16 +0100 | [diff] [blame] | 991 | (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) { |
Pierre-Louis Bossart | 8f98307d | 2016-08-16 18:28:22 -0500 | [diff] [blame] | 992 | /* set SSP0 to 16-bit */ |
Pierre-Louis Bossart | 038a50e | 2016-08-12 16:27:52 -0500 | [diff] [blame] | 993 | params_set_format(params, SNDRV_PCM_FORMAT_S16_LE); |
Erik Bussing | 332719b | 2020-01-15 17:46:16 +0100 | [diff] [blame] | 994 | bits = 16; |
Pierre-Louis Bossart | 038a50e | 2016-08-12 16:27:52 -0500 | [diff] [blame] | 995 | } else { |
Pierre-Louis Bossart | 038a50e | 2016-08-12 16:27:52 -0500 | [diff] [blame] | 996 | /* set SSP2 to 24-bit */ |
| 997 | params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); |
Erik Bussing | 332719b | 2020-01-15 17:46:16 +0100 | [diff] [blame] | 998 | bits = 24; |
Sebastien Guiriec | 3f27ded | 2015-12-17 20:35:39 -0600 | [diff] [blame] | 999 | } |
Erik Bussing | 332719b | 2020-01-15 17:46:16 +0100 | [diff] [blame] | 1000 | |
| 1001 | /* |
| 1002 | * Default mode for SSP configuration is TDM 4 slot, override config |
| 1003 | * with explicit setting to I2S 2ch. The word length is set with |
| 1004 | * dai_set_tdm_slot() since there is no other API exposed |
| 1005 | */ |
Kuninori Morimoto | 0d1571c | 2020-03-23 14:19:05 +0900 | [diff] [blame] | 1006 | ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0), |
Erik Bussing | 332719b | 2020-01-15 17:46:16 +0100 | [diff] [blame] | 1007 | SND_SOC_DAIFMT_I2S | |
| 1008 | SND_SOC_DAIFMT_NB_NF | |
| 1009 | SND_SOC_DAIFMT_CBS_CFS); |
| 1010 | if (ret < 0) { |
| 1011 | dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret); |
| 1012 | return ret; |
| 1013 | } |
| 1014 | |
Kuninori Morimoto | 0d1571c | 2020-03-23 14:19:05 +0900 | [diff] [blame] | 1015 | ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits); |
Erik Bussing | 332719b | 2020-01-15 17:46:16 +0100 | [diff] [blame] | 1016 | if (ret < 0) { |
| 1017 | dev_err(rtd->dev, "can't set I2S config, err %d\n", ret); |
| 1018 | return ret; |
| 1019 | } |
| 1020 | |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1021 | return 0; |
| 1022 | } |
| 1023 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1024 | static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream) |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1025 | { |
Lars-Peter Clausen | d0a1b66 | 2015-10-18 15:39:30 +0200 | [diff] [blame] | 1026 | return snd_pcm_hw_constraint_single(substream->runtime, |
| 1027 | SNDRV_PCM_HW_PARAM_RATE, 48000); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1028 | } |
| 1029 | |
Julia Lawall | 9b6fdef | 2016-10-15 16:55:49 +0200 | [diff] [blame] | 1030 | static const struct snd_soc_ops byt_rt5640_aif1_ops = { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1031 | .startup = byt_rt5640_aif1_startup, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1032 | }; |
| 1033 | |
Julia Lawall | 9b6fdef | 2016-10-15 16:55:49 +0200 | [diff] [blame] | 1034 | static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1035 | .hw_params = byt_rt5640_aif1_hw_params, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1036 | }; |
| 1037 | |
Kuninori Morimoto | e7a7128 | 2019-06-06 13:20:44 +0900 | [diff] [blame] | 1038 | SND_SOC_DAILINK_DEF(dummy, |
| 1039 | DAILINK_COMP_ARRAY(COMP_DUMMY())); |
| 1040 | |
| 1041 | SND_SOC_DAILINK_DEF(media, |
| 1042 | DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai"))); |
| 1043 | |
| 1044 | SND_SOC_DAILINK_DEF(deepbuffer, |
| 1045 | DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai"))); |
| 1046 | |
| 1047 | SND_SOC_DAILINK_DEF(ssp2_port, |
| 1048 | /* overwritten for ssp0 routing */ |
| 1049 | DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port"))); |
| 1050 | SND_SOC_DAILINK_DEF(ssp2_codec, |
| 1051 | DAILINK_COMP_ARRAY(COMP_CODEC( |
| 1052 | /* overwritten with HID */ "i2c-10EC5640:00", |
| 1053 | /* changed w/ quirk */ "rt5640-aif1"))); |
| 1054 | |
| 1055 | SND_SOC_DAILINK_DEF(platform, |
| 1056 | DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform"))); |
| 1057 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1058 | static struct snd_soc_dai_link byt_rt5640_dais[] = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1059 | [MERR_DPCM_AUDIO] = { |
| 1060 | .name = "Baytrail Audio Port", |
| 1061 | .stream_name = "Baytrail Audio", |
Takashi Iwai | 6e4cac2 | 2017-04-24 14:09:55 +0200 | [diff] [blame] | 1062 | .nonatomic = true, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1063 | .dynamic = 1, |
| 1064 | .dpcm_playback = 1, |
| 1065 | .dpcm_capture = 1, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1066 | .ops = &byt_rt5640_aif1_ops, |
Kuninori Morimoto | e7a7128 | 2019-06-06 13:20:44 +0900 | [diff] [blame] | 1067 | SND_SOC_DAILINK_REG(media, dummy, platform), |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1068 | }, |
Pierre-Louis Bossart | d35eb96 | 2015-12-17 20:35:45 -0600 | [diff] [blame] | 1069 | [MERR_DPCM_DEEP_BUFFER] = { |
| 1070 | .name = "Deep-Buffer Audio Port", |
| 1071 | .stream_name = "Deep-Buffer Audio", |
Pierre-Louis Bossart | d35eb96 | 2015-12-17 20:35:45 -0600 | [diff] [blame] | 1072 | .nonatomic = true, |
| 1073 | .dynamic = 1, |
| 1074 | .dpcm_playback = 1, |
| 1075 | .ops = &byt_rt5640_aif1_ops, |
Kuninori Morimoto | e7a7128 | 2019-06-06 13:20:44 +0900 | [diff] [blame] | 1076 | SND_SOC_DAILINK_REG(deepbuffer, dummy, platform), |
Pierre-Louis Bossart | d35eb96 | 2015-12-17 20:35:45 -0600 | [diff] [blame] | 1077 | }, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1078 | /* back ends */ |
| 1079 | { |
| 1080 | .name = "SSP2-Codec", |
Pierre-Louis Bossart | 149f775 | 2017-10-12 18:38:04 -0500 | [diff] [blame] | 1081 | .id = 0, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1082 | .no_pcm = 1, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1083 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 1084 | | SND_SOC_DAIFMT_CBS_CFS, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1085 | .be_hw_params_fixup = byt_rt5640_codec_fixup, |
Takashi Iwai | 6e4cac2 | 2017-04-24 14:09:55 +0200 | [diff] [blame] | 1086 | .nonatomic = true, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1087 | .dpcm_playback = 1, |
| 1088 | .dpcm_capture = 1, |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 1089 | .init = byt_rt5640_init, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1090 | .ops = &byt_rt5640_be_ssp2_ops, |
Kuninori Morimoto | e7a7128 | 2019-06-06 13:20:44 +0900 | [diff] [blame] | 1091 | SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform), |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1092 | }, |
| 1093 | }; |
| 1094 | |
| 1095 | /* SoC card */ |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 1096 | static char byt_rt5640_codec_name[SND_ACPI_I2C_ID_LEN]; |
Jaroslav Kysela | b5706f8 | 2019-12-04 15:15:46 -0600 | [diff] [blame] | 1097 | #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES) |
Hans de Goede | 063422c | 2018-05-13 09:24:35 +0200 | [diff] [blame] | 1098 | static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */ |
Jaroslav Kysela | b5706f8 | 2019-12-04 15:15:46 -0600 | [diff] [blame] | 1099 | #endif |
Jaroslav Kysela | 0d5c818 | 2019-12-04 15:15:45 -0600 | [diff] [blame] | 1100 | static char byt_rt5640_components[32]; /* = "cfg-spk:* cfg-mic:*" */ |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 1101 | |
| 1102 | static int byt_rt5640_suspend(struct snd_soc_card *card) |
| 1103 | { |
| 1104 | struct snd_soc_component *component; |
| 1105 | |
| 1106 | if (!BYT_RT5640_JDSRC(byt_rt5640_quirk)) |
| 1107 | return 0; |
| 1108 | |
Kuninori Morimoto | f70f18f7 | 2018-09-18 01:29:55 +0000 | [diff] [blame] | 1109 | for_each_card_components(card, component) { |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 1110 | if (!strcmp(component->name, byt_rt5640_codec_name)) { |
| 1111 | dev_dbg(component->dev, "disabling jack detect before suspend\n"); |
| 1112 | snd_soc_component_set_jack(component, NULL, NULL); |
| 1113 | break; |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | static int byt_rt5640_resume(struct snd_soc_card *card) |
| 1121 | { |
| 1122 | struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card); |
| 1123 | struct snd_soc_component *component; |
| 1124 | |
| 1125 | if (!BYT_RT5640_JDSRC(byt_rt5640_quirk)) |
| 1126 | return 0; |
| 1127 | |
Kuninori Morimoto | f70f18f7 | 2018-09-18 01:29:55 +0000 | [diff] [blame] | 1128 | for_each_card_components(card, component) { |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 1129 | if (!strcmp(component->name, byt_rt5640_codec_name)) { |
| 1130 | dev_dbg(component->dev, "re-enabling jack detect after resume\n"); |
| 1131 | snd_soc_component_set_jack(component, &priv->jack, NULL); |
| 1132 | break; |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | return 0; |
| 1137 | } |
| 1138 | |
Pierre-Louis Bossart | b4ecd58 | 2020-06-17 11:56:14 -0500 | [diff] [blame] | 1139 | /* use space before codec name to simplify card ID, and simplify driver name */ |
Pierre-Louis Bossart | 41656c3 | 2020-11-12 16:38:16 -0600 | [diff] [blame] | 1140 | #define SOF_CARD_NAME "bytcht rt5640" /* card name will be 'sof-bytcht rt5640' */ |
| 1141 | #define SOF_DRIVER_NAME "SOF" |
| 1142 | |
Pierre-Louis Bossart | b4ecd58 | 2020-06-17 11:56:14 -0500 | [diff] [blame] | 1143 | #define CARD_NAME "bytcr-rt5640" |
| 1144 | #define DRIVER_NAME NULL /* card name will be used for driver name */ |
Pierre-Louis Bossart | b4ecd58 | 2020-06-17 11:56:14 -0500 | [diff] [blame] | 1145 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 1146 | static struct snd_soc_card byt_rt5640_card = { |
Axel Lin | 54d8697 | 2015-08-21 20:59:21 +0800 | [diff] [blame] | 1147 | .owner = THIS_MODULE, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1148 | .dai_link = byt_rt5640_dais, |
| 1149 | .num_links = ARRAY_SIZE(byt_rt5640_dais), |
| 1150 | .dapm_widgets = byt_rt5640_widgets, |
| 1151 | .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets), |
| 1152 | .dapm_routes = byt_rt5640_audio_map, |
| 1153 | .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map), |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 1154 | .fully_routed = true, |
Hans de Goede | 7732310 | 2018-05-13 09:24:28 +0200 | [diff] [blame] | 1155 | .suspend_pre = byt_rt5640_suspend, |
| 1156 | .resume_post = byt_rt5640_resume, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1157 | }; |
| 1158 | |
Pierre-Louis Bossart | 64e8430 | 2016-11-12 18:07:45 -0600 | [diff] [blame] | 1159 | struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */ |
| 1160 | u64 aif_value; /* 1: AIF1, 2: AIF2 */ |
| 1161 | u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */ |
| 1162 | }; |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 1163 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1164 | static int snd_byt_rt5640_mc_probe(struct platform_device *pdev) |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1165 | { |
Pierre-Louis Bossart | 05ff312 | 2020-11-12 16:38:17 -0600 | [diff] [blame^] | 1166 | struct device *dev = &pdev->dev; |
Colin Ian King | 4ffdca6 | 2019-01-24 17:37:35 +0000 | [diff] [blame] | 1167 | static const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3" }; |
Hans de Goede | 6d1bfcc | 2018-05-13 09:24:33 +0200 | [diff] [blame] | 1168 | const struct dmi_system_id *dmi_id; |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 1169 | struct byt_rt5640_private *priv; |
Pierre-Louis Bossart | 7feb2f7 | 2017-10-12 18:49:38 -0500 | [diff] [blame] | 1170 | struct snd_soc_acpi_mach *mach; |
Pierre-Louis Bossart | bd7661b | 2019-01-25 14:34:59 -0600 | [diff] [blame] | 1171 | const char *platform_name; |
Andy Shevchenko | a320d89 | 2019-03-28 19:17:25 +0200 | [diff] [blame] | 1172 | struct acpi_device *adev; |
Pierre-Louis Bossart | 41656c3 | 2020-11-12 16:38:16 -0600 | [diff] [blame] | 1173 | bool sof_parent; |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 1174 | int ret_val = 0; |
Pierre-Louis Bossart | 2193eb9 | 2017-10-12 18:38:05 -0500 | [diff] [blame] | 1175 | int dai_index = 0; |
Pierre-Louis Bossart | 17b5273 | 2017-10-12 18:37:58 -0500 | [diff] [blame] | 1176 | int i; |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 1177 | |
Pierre-Louis Bossart | cb67d76 | 2017-04-24 16:34:33 -0500 | [diff] [blame] | 1178 | is_bytcr = false; |
Jia-Ju Bai | 7a3a632 | 2018-04-09 18:47:37 +0800 | [diff] [blame] | 1179 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 1180 | if (!priv) |
| 1181 | return -ENOMEM; |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1182 | |
| 1183 | /* register the soc card */ |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 1184 | byt_rt5640_card.dev = &pdev->dev; |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 1185 | mach = byt_rt5640_card.dev->platform_data; |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 1186 | snd_soc_card_set_drvdata(&byt_rt5640_card, priv); |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 1187 | |
Pierre-Louis Bossart | a232b96 | 2016-03-03 21:36:38 -0600 | [diff] [blame] | 1188 | /* fix index of codec dai */ |
Pierre-Louis Bossart | a232b96 | 2016-03-03 21:36:38 -0600 | [diff] [blame] | 1189 | for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) { |
Kuninori Morimoto | e7a7128 | 2019-06-06 13:20:44 +0900 | [diff] [blame] | 1190 | if (!strcmp(byt_rt5640_dais[i].codecs->name, |
| 1191 | "i2c-10EC5640:00")) { |
Pierre-Louis Bossart | a232b96 | 2016-03-03 21:36:38 -0600 | [diff] [blame] | 1192 | dai_index = i; |
| 1193 | break; |
| 1194 | } |
| 1195 | } |
| 1196 | |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 1197 | /* fixup codec name based on HID */ |
Andy Shevchenko | a320d89 | 2019-03-28 19:17:25 +0200 | [diff] [blame] | 1198 | adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1); |
| 1199 | if (adev) { |
Pierre-Louis Bossart | a232b96 | 2016-03-03 21:36:38 -0600 | [diff] [blame] | 1200 | snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name), |
Andy Shevchenko | a320d89 | 2019-03-28 19:17:25 +0200 | [diff] [blame] | 1201 | "i2c-%s", acpi_dev_name(adev)); |
| 1202 | put_device(&adev->dev); |
Kuninori Morimoto | e7a7128 | 2019-06-06 13:20:44 +0900 | [diff] [blame] | 1203 | byt_rt5640_dais[dai_index].codecs->name = byt_rt5640_codec_name; |
Pierre-Louis Bossart | a232b96 | 2016-03-03 21:36:38 -0600 | [diff] [blame] | 1204 | } |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1205 | |
Pierre-Louis Bossart | e214f5e | 2016-08-12 16:27:53 -0500 | [diff] [blame] | 1206 | /* |
| 1207 | * swap SSP0 if bytcr is detected |
| 1208 | * (will be overridden if DMI quirk is detected) |
| 1209 | */ |
Pierre-Louis Bossart | 536cfd2 | 2019-05-30 06:50:11 -0500 | [diff] [blame] | 1210 | if (soc_intel_is_byt()) { |
Pierre-Louis Bossart | 3ee1cd4 | 2018-11-01 16:34:50 -0500 | [diff] [blame] | 1211 | if (mach->mach_params.acpi_ipc_irq_index == 0) |
Pierre-Louis Bossart | 64e8430 | 2016-11-12 18:07:45 -0600 | [diff] [blame] | 1212 | is_bytcr = true; |
| 1213 | } |
| 1214 | |
| 1215 | if (is_bytcr) { |
| 1216 | /* |
| 1217 | * Baytrail CR platforms may have CHAN package in BIOS, try |
| 1218 | * to find relevant routing quirk based as done on Windows |
| 1219 | * platforms. We have to read the information directly from the |
| 1220 | * BIOS, at this stage the card is not created and the links |
| 1221 | * with the codec driver/pdata are non-existent |
| 1222 | */ |
| 1223 | |
| 1224 | struct acpi_chan_package chan_package; |
| 1225 | |
| 1226 | /* format specified: 2 64-bit integers */ |
| 1227 | struct acpi_buffer format = {sizeof("NN"), "NN"}; |
| 1228 | struct acpi_buffer state = {0, NULL}; |
Pierre-Louis Bossart | 7feb2f7 | 2017-10-12 18:49:38 -0500 | [diff] [blame] | 1229 | struct snd_soc_acpi_package_context pkg_ctx; |
Pierre-Louis Bossart | 64e8430 | 2016-11-12 18:07:45 -0600 | [diff] [blame] | 1230 | bool pkg_found = false; |
| 1231 | |
| 1232 | state.length = sizeof(chan_package); |
| 1233 | state.pointer = &chan_package; |
| 1234 | |
| 1235 | pkg_ctx.name = "CHAN"; |
| 1236 | pkg_ctx.length = 2; |
| 1237 | pkg_ctx.format = &format; |
| 1238 | pkg_ctx.state = &state; |
| 1239 | pkg_ctx.data_valid = false; |
| 1240 | |
Pierre-Louis Bossart | 7feb2f7 | 2017-10-12 18:49:38 -0500 | [diff] [blame] | 1241 | pkg_found = snd_soc_acpi_find_package_from_hid(mach->id, |
| 1242 | &pkg_ctx); |
Pierre-Louis Bossart | 64e8430 | 2016-11-12 18:07:45 -0600 | [diff] [blame] | 1243 | if (pkg_found) { |
| 1244 | if (chan_package.aif_value == 1) { |
| 1245 | dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n"); |
| 1246 | byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1; |
| 1247 | } else if (chan_package.aif_value == 2) { |
| 1248 | dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n"); |
| 1249 | byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2; |
| 1250 | } else { |
| 1251 | dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n"); |
| 1252 | pkg_found = false; |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | if (!pkg_found) { |
| 1257 | /* no BIOS indications, assume SSP0-AIF2 connection */ |
Pierre-Louis Bossart | e214f5e | 2016-08-12 16:27:53 -0500 | [diff] [blame] | 1258 | byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2; |
| 1259 | } |
Pierre-Louis Bossart | bf46241 | 2016-11-12 18:07:46 -0600 | [diff] [blame] | 1260 | |
| 1261 | /* change defaults for Baytrail-CR capture */ |
Hans de Goede | 96a388fe | 2018-05-13 09:24:30 +0200 | [diff] [blame] | 1262 | byt_rt5640_quirk |= BYTCR_INPUT_DEFAULTS; |
Pierre-Louis Bossart | bf46241 | 2016-11-12 18:07:46 -0600 | [diff] [blame] | 1263 | } else { |
Hans de Goede | 56ff440 | 2018-05-13 09:24:31 +0200 | [diff] [blame] | 1264 | byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP | |
| 1265 | BYT_RT5640_JD_SRC_JD2_IN4N | |
| 1266 | BYT_RT5640_OVCD_TH_2000UA | |
| 1267 | BYT_RT5640_OVCD_SF_0P75; |
Pierre-Louis Bossart | e214f5e | 2016-08-12 16:27:53 -0500 | [diff] [blame] | 1268 | } |
| 1269 | |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 1270 | /* check quirks before creating card */ |
Hans de Goede | 6d1bfcc | 2018-05-13 09:24:33 +0200 | [diff] [blame] | 1271 | dmi_id = dmi_first_match(byt_rt5640_quirk_table); |
| 1272 | if (dmi_id) |
| 1273 | byt_rt5640_quirk = (unsigned long)dmi_id->driver_data; |
Pierre-Louis Bossart | 2fb2a19 | 2019-04-19 15:12:17 -0500 | [diff] [blame] | 1274 | if (quirk_override != -1) { |
Pierre-Louis Bossart | 2697f3a | 2020-06-25 14:12:57 -0500 | [diff] [blame] | 1275 | dev_info(&pdev->dev, "Overriding quirk 0x%lx => 0x%x\n", |
| 1276 | byt_rt5640_quirk, quirk_override); |
Takashi Iwai | 9f2cf73 | 2017-04-23 09:22:56 +0200 | [diff] [blame] | 1277 | byt_rt5640_quirk = quirk_override; |
| 1278 | } |
Hans de Goede | 6a7c05e | 2018-05-08 17:35:54 +0200 | [diff] [blame] | 1279 | |
| 1280 | /* Must be called before register_card, also see declaration comment. */ |
| 1281 | ret_val = byt_rt5640_add_codec_device_props(byt_rt5640_codec_name); |
| 1282 | if (ret_val) |
| 1283 | return ret_val; |
| 1284 | |
Pierre-Louis Bossart | d7e60d5 | 2016-08-12 16:28:00 -0500 | [diff] [blame] | 1285 | log_quirks(&pdev->dev); |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 1286 | |
Pierre-Louis Bossart | f47088d | 2016-08-12 16:27:51 -0500 | [diff] [blame] | 1287 | if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) || |
Nariman Etemadi | 2968683 | 2020-01-15 17:46:17 +0100 | [diff] [blame] | 1288 | (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) |
| 1289 | byt_rt5640_dais[dai_index].codecs->dai_name = "rt5640-aif2"; |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame] | 1290 | |
Pierre-Louis Bossart | f47088d | 2016-08-12 16:27:51 -0500 | [diff] [blame] | 1291 | if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) || |
Nariman Etemadi | 2968683 | 2020-01-15 17:46:17 +0100 | [diff] [blame] | 1292 | (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) |
| 1293 | byt_rt5640_dais[dai_index].cpus->dai_name = "ssp0-port"; |
Pierre-Louis Bossart | f47088d | 2016-08-12 16:27:51 -0500 | [diff] [blame] | 1294 | |
Pierre-Louis Bossart | 7735bce | 2017-09-08 12:43:52 -0500 | [diff] [blame] | 1295 | if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) { |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 1296 | priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3"); |
| 1297 | if (IS_ERR(priv->mclk)) { |
Pierre-Louis Bossart | 4a8b3a6 | 2016-12-16 10:55:49 -0600 | [diff] [blame] | 1298 | ret_val = PTR_ERR(priv->mclk); |
| 1299 | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 1300 | dev_err(&pdev->dev, |
Pierre-Louis Bossart | 4a8b3a6 | 2016-12-16 10:55:49 -0600 | [diff] [blame] | 1301 | "Failed to get MCLK from pmc_plt_clk_3: %d\n", |
| 1302 | ret_val); |
| 1303 | |
| 1304 | /* |
| 1305 | * Fall back to bit clock usage for -ENOENT (clock not |
| 1306 | * available likely due to missing dependencies), bail |
| 1307 | * for all other errors, including -EPROBE_DEFER |
| 1308 | */ |
| 1309 | if (ret_val != -ENOENT) |
| 1310 | return ret_val; |
| 1311 | byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN; |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 1312 | } |
| 1313 | } |
| 1314 | |
Jaroslav Kysela | 0d5c818 | 2019-12-04 15:15:45 -0600 | [diff] [blame] | 1315 | snprintf(byt_rt5640_components, sizeof(byt_rt5640_components), |
| 1316 | "cfg-spk:%s cfg-mic:%s", |
| 1317 | (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) ? "1" : "2", |
| 1318 | map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]); |
| 1319 | byt_rt5640_card.components = byt_rt5640_components; |
Jaroslav Kysela | b5706f8 | 2019-12-04 15:15:46 -0600 | [diff] [blame] | 1320 | #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES) |
Hans de Goede | 063422c | 2018-05-13 09:24:35 +0200 | [diff] [blame] | 1321 | snprintf(byt_rt5640_long_name, sizeof(byt_rt5640_long_name), |
| 1322 | "bytcr-rt5640-%s-spk-%s-mic", |
| 1323 | (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) ? |
| 1324 | "mono" : "stereo", |
| 1325 | map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]); |
| 1326 | byt_rt5640_card.long_name = byt_rt5640_long_name; |
Jaroslav Kysela | b5706f8 | 2019-12-04 15:15:46 -0600 | [diff] [blame] | 1327 | #endif |
Hans de Goede | 063422c | 2018-05-13 09:24:35 +0200 | [diff] [blame] | 1328 | |
Pierre-Louis Bossart | bd7661b | 2019-01-25 14:34:59 -0600 | [diff] [blame] | 1329 | /* override plaform name, if required */ |
| 1330 | platform_name = mach->mach_params.platform; |
| 1331 | |
| 1332 | ret_val = snd_soc_fixup_dai_links_platform_name(&byt_rt5640_card, |
| 1333 | platform_name); |
| 1334 | if (ret_val) |
| 1335 | return ret_val; |
| 1336 | |
Pierre-Louis Bossart | 41656c3 | 2020-11-12 16:38:16 -0600 | [diff] [blame] | 1337 | sof_parent = snd_soc_acpi_sof_parent(&pdev->dev); |
| 1338 | |
| 1339 | /* set card and driver name */ |
| 1340 | if (sof_parent) { |
| 1341 | byt_rt5640_card.name = SOF_CARD_NAME; |
| 1342 | byt_rt5640_card.driver_name = SOF_DRIVER_NAME; |
| 1343 | } else { |
| 1344 | byt_rt5640_card.name = CARD_NAME; |
| 1345 | byt_rt5640_card.driver_name = DRIVER_NAME; |
| 1346 | } |
| 1347 | |
Pierre-Louis Bossart | 05ff312 | 2020-11-12 16:38:17 -0600 | [diff] [blame^] | 1348 | /* set pm ops */ |
| 1349 | if (sof_parent) |
| 1350 | dev->driver->pm = &snd_soc_pm_ops; |
| 1351 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 1352 | ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card); |
| 1353 | |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1354 | if (ret_val) { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1355 | dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n", |
| 1356 | ret_val); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1357 | return ret_val; |
| 1358 | } |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 1359 | platform_set_drvdata(pdev, &byt_rt5640_card); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1360 | return ret_val; |
| 1361 | } |
| 1362 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1363 | static struct platform_driver snd_byt_rt5640_mc_driver = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1364 | .driver = { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1365 | .name = "bytcr_rt5640", |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1366 | }, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1367 | .probe = snd_byt_rt5640_mc_probe, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1368 | }; |
| 1369 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1370 | module_platform_driver(snd_byt_rt5640_mc_driver); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1371 | |
| 1372 | MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver"); |
| 1373 | MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>"); |
| 1374 | MODULE_LICENSE("GPL v2"); |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 1375 | MODULE_ALIAS("platform:bytcr_rt5640"); |