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