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