Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 1 | /* |
| 2 | * bytcr_rt5651.c - ASoc Machine driver for Intel Byt CR platform |
| 3 | * (derived from bytcr_rt5640.c) |
| 4 | * |
| 5 | * Copyright (C) 2015 Intel Corp |
| 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 | |
| 20 | #include <linux/init.h> |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 21 | #include <linux/i2c.h> |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | #include <linux/platform_device.h> |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 24 | #include <linux/property.h> |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 25 | #include <linux/acpi.h> |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 26 | #include <linux/clk.h> |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 27 | #include <linux/device.h> |
| 28 | #include <linux/dmi.h> |
Hans de Goede | caed9d63 | 2018-07-05 00:59:35 +0200 | [diff] [blame] | 29 | #include <linux/input.h> |
Hans de Goede | 5f6fb23 | 2018-07-01 20:36:31 +0200 | [diff] [blame] | 30 | #include <linux/gpio/consumer.h> |
| 31 | #include <linux/gpio/machine.h> |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 32 | #include <linux/slab.h> |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 33 | #include <asm/cpu_device_id.h> |
Hans de Goede | fbea16d | 2018-07-01 20:36:29 +0200 | [diff] [blame] | 34 | #include <asm/intel-family.h> |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 35 | #include <sound/pcm.h> |
| 36 | #include <sound/pcm_params.h> |
| 37 | #include <sound/soc.h> |
| 38 | #include <sound/jack.h> |
Pierre-Louis Bossart | 7feb2f7 | 2017-10-12 18:49:38 -0500 | [diff] [blame] | 39 | #include <sound/soc-acpi.h> |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 40 | #include "../../codecs/rt5651.h" |
| 41 | #include "../atom/sst-atom-controls.h" |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 42 | |
| 43 | enum { |
| 44 | BYT_RT5651_DMIC_MAP, |
| 45 | BYT_RT5651_IN1_MAP, |
Hans de Goede | ac275ee | 2018-07-18 22:55:40 +0200 | [diff] [blame] | 46 | BYT_RT5651_IN2_MAP, |
Carlo Caione | ea261bd | 2017-11-21 17:15:45 +0000 | [diff] [blame] | 47 | BYT_RT5651_IN1_IN2_MAP, |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 48 | }; |
| 49 | |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 50 | enum { |
| 51 | BYT_RT5651_JD_NULL = (RT5651_JD_NULL << 4), |
| 52 | BYT_RT5651_JD1_1 = (RT5651_JD1_1 << 4), |
| 53 | BYT_RT5651_JD1_2 = (RT5651_JD1_2 << 4), |
| 54 | BYT_RT5651_JD2 = (RT5651_JD2 << 4), |
| 55 | }; |
| 56 | |
Hans de Goede | 8ffaa6a | 2018-03-04 15:36:02 +0100 | [diff] [blame] | 57 | enum { |
| 58 | BYT_RT5651_OVCD_TH_600UA = (6 << 8), |
| 59 | BYT_RT5651_OVCD_TH_1500UA = (15 << 8), |
| 60 | BYT_RT5651_OVCD_TH_2000UA = (20 << 8), |
| 61 | }; |
| 62 | |
| 63 | enum { |
| 64 | BYT_RT5651_OVCD_SF_0P5 = (RT5651_OVCD_SF_0P5 << 13), |
| 65 | BYT_RT5651_OVCD_SF_0P75 = (RT5651_OVCD_SF_0P75 << 13), |
| 66 | BYT_RT5651_OVCD_SF_1P0 = (RT5651_OVCD_SF_1P0 << 13), |
| 67 | BYT_RT5651_OVCD_SF_1P5 = (RT5651_OVCD_SF_1P5 << 13), |
| 68 | }; |
| 69 | |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 70 | #define BYT_RT5651_MAP(quirk) ((quirk) & GENMASK(3, 0)) |
| 71 | #define BYT_RT5651_JDSRC(quirk) (((quirk) & GENMASK(7, 4)) >> 4) |
Hans de Goede | 8ffaa6a | 2018-03-04 15:36:02 +0100 | [diff] [blame] | 72 | #define BYT_RT5651_OVCD_TH(quirk) (((quirk) & GENMASK(12, 8)) >> 8) |
| 73 | #define BYT_RT5651_OVCD_SF(quirk) (((quirk) & GENMASK(14, 13)) >> 13) |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 74 | #define BYT_RT5651_DMIC_EN BIT(16) |
| 75 | #define BYT_RT5651_MCLK_EN BIT(17) |
| 76 | #define BYT_RT5651_MCLK_25MHZ BIT(18) |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 77 | #define BYT_RT5651_SSP2_AIF2 BIT(19) /* default is using AIF1 */ |
| 78 | #define BYT_RT5651_SSP0_AIF1 BIT(20) |
| 79 | #define BYT_RT5651_SSP0_AIF2 BIT(21) |
Hans de Goede | 8f250e7 | 2018-06-24 16:06:33 +0200 | [diff] [blame] | 80 | #define BYT_RT5651_HP_LR_SWAPPED BIT(22) |
Hans de Goede | a0d1d86 | 2018-07-18 22:55:41 +0200 | [diff] [blame] | 81 | #define BYT_RT5651_MONO_SPEAKER BIT(23) |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 82 | |
Hans de Goede | fc7c460 | 2018-06-24 16:06:26 +0200 | [diff] [blame] | 83 | #define BYT_RT5651_DEFAULT_QUIRKS (BYT_RT5651_MCLK_EN | \ |
| 84 | BYT_RT5651_JD1_1 | \ |
| 85 | BYT_RT5651_OVCD_TH_2000UA | \ |
| 86 | BYT_RT5651_OVCD_SF_0P75) |
| 87 | |
Hans de Goede | 8ffaa6a | 2018-03-04 15:36:02 +0100 | [diff] [blame] | 88 | /* jack-detect-source + dmic-en + ovcd-th + -sf + terminating empty entry */ |
| 89 | #define MAX_NO_PROPS 5 |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 90 | |
| 91 | struct byt_rt5651_private { |
| 92 | struct clk *mclk; |
Hans de Goede | 5f6fb23 | 2018-07-01 20:36:31 +0200 | [diff] [blame] | 93 | struct gpio_desc *ext_amp_gpio; |
Hans de Goede | 90768ea | 2018-12-30 00:00:24 +0100 | [diff] [blame] | 94 | struct gpio_desc *hp_detect; |
Carlo Caione | d9f8f9b | 2017-10-20 12:18:56 +0100 | [diff] [blame] | 95 | struct snd_soc_jack jack; |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 96 | }; |
| 97 | |
Hans de Goede | fee3e1c | 2018-12-30 00:00:25 +0100 | [diff] [blame] | 98 | static const struct acpi_gpio_mapping *byt_rt5651_gpios; |
| 99 | |
Hans de Goede | ac275ee | 2018-07-18 22:55:40 +0200 | [diff] [blame] | 100 | /* Default: jack-detect on JD1_1, internal mic on in2, headsetmic on in3 */ |
Hans de Goede | fc7c460 | 2018-06-24 16:06:26 +0200 | [diff] [blame] | 101 | static unsigned long byt_rt5651_quirk = BYT_RT5651_DEFAULT_QUIRKS | |
Hans de Goede | ac275ee | 2018-07-18 22:55:40 +0200 | [diff] [blame] | 102 | BYT_RT5651_IN2_MAP; |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 103 | |
Hans de Goede | 7eb1873 | 2018-12-30 00:00:23 +0100 | [diff] [blame] | 104 | static unsigned int quirk_override; |
| 105 | module_param_named(quirk, quirk_override, uint, 0444); |
| 106 | MODULE_PARM_DESC(quirk, "Board-specific quirk override"); |
| 107 | |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 108 | static void log_quirks(struct device *dev) |
| 109 | { |
| 110 | if (BYT_RT5651_MAP(byt_rt5651_quirk) == BYT_RT5651_DMIC_MAP) |
| 111 | dev_info(dev, "quirk DMIC_MAP enabled"); |
| 112 | if (BYT_RT5651_MAP(byt_rt5651_quirk) == BYT_RT5651_IN1_MAP) |
| 113 | dev_info(dev, "quirk IN1_MAP enabled"); |
Hans de Goede | ac275ee | 2018-07-18 22:55:40 +0200 | [diff] [blame] | 114 | if (BYT_RT5651_MAP(byt_rt5651_quirk) == BYT_RT5651_IN2_MAP) |
| 115 | dev_info(dev, "quirk IN2_MAP enabled"); |
Hans de Goede | 366780d | 2018-06-24 16:06:28 +0200 | [diff] [blame] | 116 | if (BYT_RT5651_MAP(byt_rt5651_quirk) == BYT_RT5651_IN1_IN2_MAP) |
| 117 | dev_info(dev, "quirk IN1_IN2_MAP enabled"); |
Hans de Goede | 8ffaa6a | 2018-03-04 15:36:02 +0100 | [diff] [blame] | 118 | if (BYT_RT5651_JDSRC(byt_rt5651_quirk)) { |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 119 | dev_info(dev, "quirk realtek,jack-detect-source %ld\n", |
| 120 | BYT_RT5651_JDSRC(byt_rt5651_quirk)); |
Hans de Goede | 8ffaa6a | 2018-03-04 15:36:02 +0100 | [diff] [blame] | 121 | dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n", |
| 122 | BYT_RT5651_OVCD_TH(byt_rt5651_quirk) * 100); |
| 123 | dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n", |
| 124 | BYT_RT5651_OVCD_SF(byt_rt5651_quirk)); |
| 125 | } |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 126 | if (byt_rt5651_quirk & BYT_RT5651_DMIC_EN) |
| 127 | dev_info(dev, "quirk DMIC enabled"); |
| 128 | if (byt_rt5651_quirk & BYT_RT5651_MCLK_EN) |
| 129 | dev_info(dev, "quirk MCLK_EN enabled"); |
| 130 | if (byt_rt5651_quirk & BYT_RT5651_MCLK_25MHZ) |
| 131 | dev_info(dev, "quirk MCLK_25MHZ enabled"); |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 132 | if (byt_rt5651_quirk & BYT_RT5651_SSP2_AIF2) |
| 133 | dev_info(dev, "quirk SSP2_AIF2 enabled\n"); |
| 134 | if (byt_rt5651_quirk & BYT_RT5651_SSP0_AIF1) |
| 135 | dev_info(dev, "quirk SSP0_AIF1 enabled\n"); |
| 136 | if (byt_rt5651_quirk & BYT_RT5651_SSP0_AIF2) |
| 137 | dev_info(dev, "quirk SSP0_AIF2 enabled\n"); |
Hans de Goede | a0d1d86 | 2018-07-18 22:55:41 +0200 | [diff] [blame] | 138 | if (byt_rt5651_quirk & BYT_RT5651_MONO_SPEAKER) |
| 139 | dev_info(dev, "quirk MONO_SPEAKER enabled\n"); |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | #define BYT_CODEC_DAI1 "rt5651-aif1" |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 143 | #define BYT_CODEC_DAI2 "rt5651-aif2" |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 144 | |
Hans de Goede | aeec6cc | 2018-03-04 15:36:03 +0100 | [diff] [blame] | 145 | static int byt_rt5651_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai, |
| 146 | int rate, int bclk_ratio) |
| 147 | { |
| 148 | int clk_id, clk_freq, ret; |
| 149 | |
| 150 | /* Configure the PLL before selecting it */ |
| 151 | if (!(byt_rt5651_quirk & BYT_RT5651_MCLK_EN)) { |
| 152 | clk_id = RT5651_PLL1_S_BCLK1, |
| 153 | clk_freq = rate * bclk_ratio; |
| 154 | } else { |
| 155 | clk_id = RT5651_PLL1_S_MCLK; |
| 156 | if (byt_rt5651_quirk & BYT_RT5651_MCLK_25MHZ) |
| 157 | clk_freq = 25000000; |
| 158 | else |
| 159 | clk_freq = 19200000; |
| 160 | } |
| 161 | ret = snd_soc_dai_set_pll(codec_dai, 0, clk_id, clk_freq, rate * 512); |
| 162 | if (ret < 0) { |
Kuninori Morimoto | 2759ba9 | 2018-03-28 01:49:36 +0000 | [diff] [blame] | 163 | dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret); |
Hans de Goede | aeec6cc | 2018-03-04 15:36:03 +0100 | [diff] [blame] | 164 | return ret; |
| 165 | } |
| 166 | |
| 167 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5651_SCLK_S_PLL1, |
| 168 | rate * 512, SND_SOC_CLOCK_IN); |
| 169 | if (ret < 0) { |
Kuninori Morimoto | 2759ba9 | 2018-03-28 01:49:36 +0000 | [diff] [blame] | 170 | dev_err(codec_dai->component->dev, "can't set clock %d\n", ret); |
Hans de Goede | aeec6cc | 2018-03-04 15:36:03 +0100 | [diff] [blame] | 171 | return ret; |
| 172 | } |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 177 | static int platform_clock_control(struct snd_soc_dapm_widget *w, |
| 178 | struct snd_kcontrol *k, int event) |
| 179 | { |
| 180 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 181 | struct snd_soc_card *card = dapm->card; |
| 182 | struct snd_soc_dai *codec_dai; |
| 183 | struct byt_rt5651_private *priv = snd_soc_card_get_drvdata(card); |
| 184 | int ret; |
| 185 | |
Pierre-Louis Bossart | dfb6ec7 | 2017-10-12 18:38:03 -0500 | [diff] [blame] | 186 | codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1); |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 187 | if (!codec_dai) |
| 188 | codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2); |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 189 | if (!codec_dai) { |
| 190 | dev_err(card->dev, |
| 191 | "Codec dai not found; Unable to set platform clock\n"); |
| 192 | return -EIO; |
| 193 | } |
| 194 | |
| 195 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
| 196 | if (byt_rt5651_quirk & BYT_RT5651_MCLK_EN) { |
| 197 | ret = clk_prepare_enable(priv->mclk); |
| 198 | if (ret < 0) { |
| 199 | dev_err(card->dev, |
| 200 | "could not configure MCLK state"); |
| 201 | return ret; |
| 202 | } |
| 203 | } |
Hans de Goede | aeec6cc | 2018-03-04 15:36:03 +0100 | [diff] [blame] | 204 | ret = byt_rt5651_prepare_and_enable_pll1(codec_dai, 48000, 50); |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 205 | } else { |
| 206 | /* |
| 207 | * Set codec clock source to internal clock before |
| 208 | * turning off the platform clock. Codec needs clock |
| 209 | * for Jack detection and button press |
| 210 | */ |
| 211 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5651_SCLK_S_RCCLK, |
| 212 | 48000 * 512, |
| 213 | SND_SOC_CLOCK_IN); |
| 214 | if (!ret) |
| 215 | if (byt_rt5651_quirk & BYT_RT5651_MCLK_EN) |
| 216 | clk_disable_unprepare(priv->mclk); |
| 217 | } |
| 218 | |
| 219 | if (ret < 0) { |
| 220 | dev_err(card->dev, "can't set codec sysclk: %d\n", ret); |
| 221 | return ret; |
| 222 | } |
| 223 | |
| 224 | return 0; |
| 225 | } |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 226 | |
Hans de Goede | 5f6fb23 | 2018-07-01 20:36:31 +0200 | [diff] [blame] | 227 | static int rt5651_ext_amp_power_event(struct snd_soc_dapm_widget *w, |
| 228 | struct snd_kcontrol *kcontrol, int event) |
| 229 | { |
| 230 | struct snd_soc_card *card = w->dapm->card; |
| 231 | struct byt_rt5651_private *priv = snd_soc_card_get_drvdata(card); |
| 232 | |
| 233 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 234 | gpiod_set_value_cansleep(priv->ext_amp_gpio, 1); |
| 235 | else |
| 236 | gpiod_set_value_cansleep(priv->ext_amp_gpio, 0); |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 241 | static const struct snd_soc_dapm_widget byt_rt5651_widgets[] = { |
| 242 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 243 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 244 | SND_SOC_DAPM_MIC("Internal Mic", NULL), |
| 245 | SND_SOC_DAPM_SPK("Speaker", NULL), |
Pierre-Louis Bossart | ea39bdc | 2018-01-05 13:20:23 -0600 | [diff] [blame] | 246 | SND_SOC_DAPM_LINE("Line In", NULL), |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 247 | SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, |
| 248 | platform_clock_control, SND_SOC_DAPM_PRE_PMU | |
| 249 | SND_SOC_DAPM_POST_PMD), |
Hans de Goede | 5f6fb23 | 2018-07-01 20:36:31 +0200 | [diff] [blame] | 250 | SND_SOC_DAPM_SUPPLY("Ext Amp Power", SND_SOC_NOPM, 0, 0, |
| 251 | rt5651_ext_amp_power_event, |
| 252 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | static const struct snd_soc_dapm_route byt_rt5651_audio_map[] = { |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 256 | {"Headphone", NULL, "Platform Clock"}, |
| 257 | {"Headset Mic", NULL, "Platform Clock"}, |
| 258 | {"Internal Mic", NULL, "Platform Clock"}, |
| 259 | {"Speaker", NULL, "Platform Clock"}, |
Hans de Goede | 5f6fb23 | 2018-07-01 20:36:31 +0200 | [diff] [blame] | 260 | {"Speaker", NULL, "Ext Amp Power"}, |
Pierre-Louis Bossart | ea39bdc | 2018-01-05 13:20:23 -0600 | [diff] [blame] | 261 | {"Line In", NULL, "Platform Clock"}, |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 262 | |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 263 | {"Headset Mic", NULL, "micbias1"}, /* lowercase for rt5651 */ |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 264 | {"Headphone", NULL, "HPOL"}, |
| 265 | {"Headphone", NULL, "HPOR"}, |
| 266 | {"Speaker", NULL, "LOUTL"}, |
| 267 | {"Speaker", NULL, "LOUTR"}, |
Pierre-Louis Bossart | ea39bdc | 2018-01-05 13:20:23 -0600 | [diff] [blame] | 268 | {"IN2P", NULL, "Line In"}, |
| 269 | {"IN2N", NULL, "Line In"}, |
| 270 | |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 271 | }; |
| 272 | |
Pierre-Louis Bossart | 6356c78 | 2017-09-08 12:43:53 -0500 | [diff] [blame] | 273 | static const struct snd_soc_dapm_route byt_rt5651_intmic_dmic_map[] = { |
| 274 | {"DMIC L1", NULL, "Internal Mic"}, |
| 275 | {"DMIC R1", NULL, "Internal Mic"}, |
Hans de Goede | aee48a9 | 2018-12-30 00:00:22 +0100 | [diff] [blame] | 276 | {"IN2P", NULL, "Headset Mic"}, |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | static const struct snd_soc_dapm_route byt_rt5651_intmic_in1_map[] = { |
| 280 | {"Internal Mic", NULL, "micbias1"}, |
| 281 | {"IN1P", NULL, "Internal Mic"}, |
Hans de Goede | de23147 | 2018-06-24 16:06:30 +0200 | [diff] [blame] | 282 | {"IN3P", NULL, "Headset Mic"}, |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 283 | }; |
| 284 | |
Hans de Goede | ac275ee | 2018-07-18 22:55:40 +0200 | [diff] [blame] | 285 | static const struct snd_soc_dapm_route byt_rt5651_intmic_in2_map[] = { |
| 286 | {"Internal Mic", NULL, "micbias1"}, |
| 287 | {"IN2P", NULL, "Internal Mic"}, |
| 288 | {"IN3P", NULL, "Headset Mic"}, |
| 289 | }; |
| 290 | |
Carlo Caione | ea261bd | 2017-11-21 17:15:45 +0000 | [diff] [blame] | 291 | static const struct snd_soc_dapm_route byt_rt5651_intmic_in1_in2_map[] = { |
| 292 | {"Internal Mic", NULL, "micbias1"}, |
| 293 | {"IN1P", NULL, "Internal Mic"}, |
| 294 | {"IN2P", NULL, "Internal Mic"}, |
| 295 | {"IN3P", NULL, "Headset Mic"}, |
| 296 | }; |
| 297 | |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 298 | static const struct snd_soc_dapm_route byt_rt5651_ssp0_aif1_map[] = { |
| 299 | {"ssp0 Tx", NULL, "modem_out"}, |
| 300 | {"modem_in", NULL, "ssp0 Rx"}, |
| 301 | |
| 302 | {"AIF1 Playback", NULL, "ssp0 Tx"}, |
| 303 | {"ssp0 Rx", NULL, "AIF1 Capture"}, |
| 304 | }; |
| 305 | |
| 306 | static const struct snd_soc_dapm_route byt_rt5651_ssp0_aif2_map[] = { |
| 307 | {"ssp0 Tx", NULL, "modem_out"}, |
| 308 | {"modem_in", NULL, "ssp0 Rx"}, |
| 309 | |
| 310 | {"AIF2 Playback", NULL, "ssp0 Tx"}, |
| 311 | {"ssp0 Rx", NULL, "AIF2 Capture"}, |
| 312 | }; |
| 313 | |
| 314 | static const struct snd_soc_dapm_route byt_rt5651_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_rt5651_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 | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 334 | static const struct snd_kcontrol_new byt_rt5651_controls[] = { |
| 335 | SOC_DAPM_PIN_SWITCH("Headphone"), |
| 336 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
| 337 | SOC_DAPM_PIN_SWITCH("Internal Mic"), |
| 338 | SOC_DAPM_PIN_SWITCH("Speaker"), |
Pierre-Louis Bossart | ea39bdc | 2018-01-05 13:20:23 -0600 | [diff] [blame] | 339 | SOC_DAPM_PIN_SWITCH("Line In"), |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 340 | }; |
| 341 | |
Carlo Caione | d9f8f9b | 2017-10-20 12:18:56 +0100 | [diff] [blame] | 342 | static struct snd_soc_jack_pin bytcr_jack_pins[] = { |
| 343 | { |
| 344 | .pin = "Headphone", |
| 345 | .mask = SND_JACK_HEADPHONE, |
| 346 | }, |
| 347 | { |
| 348 | .pin = "Headset Mic", |
| 349 | .mask = SND_JACK_MICROPHONE, |
| 350 | }, |
| 351 | }; |
| 352 | |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 353 | static int byt_rt5651_aif1_hw_params(struct snd_pcm_substream *substream, |
| 354 | struct snd_pcm_hw_params *params) |
| 355 | { |
| 356 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 357 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 358 | snd_pcm_format_t format = params_format(params); |
Hans de Goede | aeec6cc | 2018-03-04 15:36:03 +0100 | [diff] [blame] | 359 | int rate = params_rate(params); |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 360 | int bclk_ratio; |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 361 | |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 362 | if (format == SNDRV_PCM_FORMAT_S16_LE) |
| 363 | bclk_ratio = 32; |
| 364 | else |
| 365 | bclk_ratio = 50; |
| 366 | |
| 367 | return byt_rt5651_prepare_and_enable_pll1(codec_dai, rate, bclk_ratio); |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 368 | } |
| 369 | |
Hans de Goede | fee3e1c | 2018-12-30 00:00:25 +0100 | [diff] [blame] | 370 | static const struct acpi_gpio_params pov_p1006w_hp_detect = { 1, 0, false }; |
| 371 | static const struct acpi_gpio_params pov_p1006w_ext_amp_en = { 2, 0, true }; |
| 372 | |
| 373 | static const struct acpi_gpio_mapping byt_rt5651_pov_p1006w_gpios[] = { |
| 374 | { "hp-detect-gpios", &pov_p1006w_hp_detect, 1, }, |
| 375 | { "ext-amp-enable-gpios", &pov_p1006w_ext_amp_en, 1, }, |
| 376 | { }, |
| 377 | }; |
| 378 | |
| 379 | static int byt_rt5651_pov_p1006w_quirk_cb(const struct dmi_system_id *id) |
| 380 | { |
| 381 | byt_rt5651_quirk = (unsigned long)id->driver_data; |
| 382 | byt_rt5651_gpios = byt_rt5651_pov_p1006w_gpios; |
| 383 | return 1; |
| 384 | } |
| 385 | |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 386 | static int byt_rt5651_quirk_cb(const struct dmi_system_id *id) |
| 387 | { |
| 388 | byt_rt5651_quirk = (unsigned long)id->driver_data; |
| 389 | return 1; |
| 390 | } |
| 391 | |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 392 | static const struct dmi_system_id byt_rt5651_quirk_table[] = { |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 393 | { |
Hans de Goede | 8f250e7 | 2018-06-24 16:06:33 +0200 | [diff] [blame] | 394 | /* Chuwi Hi8 Pro (CWI513) */ |
| 395 | .callback = byt_rt5651_quirk_cb, |
| 396 | .matches = { |
| 397 | DMI_MATCH(DMI_SYS_VENDOR, "Hampoo"), |
| 398 | DMI_MATCH(DMI_PRODUCT_NAME, "X1D3_C806N"), |
| 399 | }, |
| 400 | .driver_data = (void *)(BYT_RT5651_DEFAULT_QUIRKS | |
Hans de Goede | ac275ee | 2018-07-18 22:55:40 +0200 | [diff] [blame] | 401 | BYT_RT5651_IN2_MAP | |
Hans de Goede | a0d1d86 | 2018-07-18 22:55:41 +0200 | [diff] [blame] | 402 | BYT_RT5651_HP_LR_SWAPPED | |
| 403 | BYT_RT5651_MONO_SPEAKER), |
Hans de Goede | 8f250e7 | 2018-06-24 16:06:33 +0200 | [diff] [blame] | 404 | }, |
| 405 | { |
Hans de Goede | f026e06 | 2018-03-04 15:36:06 +0100 | [diff] [blame] | 406 | /* Chuwi Vi8 Plus (CWI519) */ |
| 407 | .callback = byt_rt5651_quirk_cb, |
| 408 | .matches = { |
| 409 | DMI_MATCH(DMI_SYS_VENDOR, "Hampoo"), |
| 410 | DMI_MATCH(DMI_PRODUCT_NAME, "D2D3_Vi8A1"), |
| 411 | }, |
Hans de Goede | fc7c460 | 2018-06-24 16:06:26 +0200 | [diff] [blame] | 412 | .driver_data = (void *)(BYT_RT5651_DEFAULT_QUIRKS | |
Hans de Goede | ac275ee | 2018-07-18 22:55:40 +0200 | [diff] [blame] | 413 | BYT_RT5651_IN2_MAP | |
Hans de Goede | a0d1d86 | 2018-07-18 22:55:41 +0200 | [diff] [blame] | 414 | BYT_RT5651_HP_LR_SWAPPED | |
| 415 | BYT_RT5651_MONO_SPEAKER), |
Hans de Goede | f026e06 | 2018-03-04 15:36:06 +0100 | [diff] [blame] | 416 | }, |
Hans de Goede | f9877eb | 2018-03-04 15:36:08 +0100 | [diff] [blame] | 417 | { |
Hans de Goede | 06aa6e5 | 2018-07-18 22:55:42 +0200 | [diff] [blame] | 418 | /* I.T.Works TW701, Ployer Momo7w and Trekstor ST70416-6 |
| 419 | * (these all use the same mainboard) */ |
| 420 | .callback = byt_rt5651_quirk_cb, |
| 421 | .matches = { |
| 422 | DMI_MATCH(DMI_BIOS_VENDOR, "INSYDE Corp."), |
| 423 | /* Partial match for all of itWORKS.G.WI71C.JGBMRBA, |
| 424 | * TREK.G.WI71C.JGBMRBA0x and MOMO.G.WI71C.MABMRBA02 */ |
| 425 | DMI_MATCH(DMI_BIOS_VERSION, ".G.WI71C."), |
| 426 | }, |
| 427 | .driver_data = (void *)(BYT_RT5651_DEFAULT_QUIRKS | |
| 428 | BYT_RT5651_IN2_MAP | |
| 429 | BYT_RT5651_SSP0_AIF1 | |
| 430 | BYT_RT5651_MONO_SPEAKER), |
| 431 | }, |
| 432 | { |
Hans de Goede | 55d69c0 | 2018-06-24 16:06:34 +0200 | [diff] [blame] | 433 | /* KIANO SlimNote 14.2 */ |
| 434 | .callback = byt_rt5651_quirk_cb, |
| 435 | .matches = { |
| 436 | DMI_MATCH(DMI_SYS_VENDOR, "KIANO"), |
| 437 | DMI_MATCH(DMI_PRODUCT_NAME, "KIANO SlimNote 14.2"), |
| 438 | }, |
| 439 | .driver_data = (void *)(BYT_RT5651_DEFAULT_QUIRKS | |
| 440 | BYT_RT5651_IN1_IN2_MAP), |
| 441 | }, |
| 442 | { |
| 443 | /* Minnowboard Max B3 */ |
| 444 | .callback = byt_rt5651_quirk_cb, |
| 445 | .matches = { |
| 446 | DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"), |
| 447 | DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"), |
| 448 | }, |
| 449 | .driver_data = (void *)(BYT_RT5651_IN1_MAP), |
| 450 | }, |
| 451 | { |
| 452 | /* Minnowboard Turbot */ |
| 453 | .callback = byt_rt5651_quirk_cb, |
| 454 | .matches = { |
| 455 | DMI_MATCH(DMI_SYS_VENDOR, "ADI"), |
| 456 | DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Turbot"), |
| 457 | }, |
| 458 | .driver_data = (void *)(BYT_RT5651_MCLK_EN | |
| 459 | BYT_RT5651_IN1_MAP), |
| 460 | }, |
| 461 | { |
Hans de Goede | fee3e1c | 2018-12-30 00:00:25 +0100 | [diff] [blame] | 462 | /* Point of View mobii wintab p1006w (v1.0) */ |
| 463 | .callback = byt_rt5651_pov_p1006w_quirk_cb, |
| 464 | .matches = { |
| 465 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"), |
| 466 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "BayTrail"), |
| 467 | /* Note 105b is Foxcon's USB/PCI vendor id */ |
| 468 | DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "105B"), |
| 469 | DMI_EXACT_MATCH(DMI_BOARD_NAME, "0E57"), |
| 470 | }, |
| 471 | .driver_data = (void *)(BYT_RT5651_DMIC_MAP | |
| 472 | BYT_RT5651_OVCD_TH_2000UA | |
| 473 | BYT_RT5651_OVCD_SF_0P75 | |
| 474 | BYT_RT5651_DMIC_EN | |
| 475 | BYT_RT5651_MCLK_EN | |
| 476 | BYT_RT5651_SSP0_AIF1), |
| 477 | }, |
| 478 | { |
Hans de Goede | f9877eb | 2018-03-04 15:36:08 +0100 | [diff] [blame] | 479 | /* VIOS LTH17 */ |
| 480 | .callback = byt_rt5651_quirk_cb, |
| 481 | .matches = { |
| 482 | DMI_MATCH(DMI_SYS_VENDOR, "VIOS"), |
| 483 | DMI_MATCH(DMI_PRODUCT_NAME, "LTH17"), |
| 484 | }, |
Hans de Goede | 8627fb2 | 2018-07-18 22:55:39 +0200 | [diff] [blame] | 485 | .driver_data = (void *)(BYT_RT5651_IN1_IN2_MAP | |
| 486 | BYT_RT5651_JD1_1 | |
| 487 | BYT_RT5651_OVCD_TH_2000UA | |
| 488 | BYT_RT5651_OVCD_SF_1P0 | |
| 489 | BYT_RT5651_MCLK_EN), |
Hans de Goede | f9877eb | 2018-03-04 15:36:08 +0100 | [diff] [blame] | 490 | }, |
Hans de Goede | 06aa6e5 | 2018-07-18 22:55:42 +0200 | [diff] [blame] | 491 | { |
| 492 | /* Yours Y8W81 (and others using the same mainboard) */ |
| 493 | .callback = byt_rt5651_quirk_cb, |
| 494 | .matches = { |
| 495 | DMI_MATCH(DMI_BIOS_VENDOR, "INSYDE Corp."), |
| 496 | /* Partial match for all devs with a W86C mainboard */ |
| 497 | DMI_MATCH(DMI_BIOS_VERSION, ".F.W86C."), |
| 498 | }, |
| 499 | .driver_data = (void *)(BYT_RT5651_DEFAULT_QUIRKS | |
| 500 | BYT_RT5651_IN2_MAP | |
| 501 | BYT_RT5651_SSP0_AIF1 | |
| 502 | BYT_RT5651_MONO_SPEAKER), |
| 503 | }, |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 504 | {} |
| 505 | }; |
| 506 | |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 507 | /* |
| 508 | * Note this MUST be called before snd_soc_register_card(), so that the props |
| 509 | * are in place before the codec component driver's probe function parses them. |
| 510 | */ |
Hans de Goede | 2c37520 | 2018-07-01 20:36:30 +0200 | [diff] [blame] | 511 | static int byt_rt5651_add_codec_device_props(struct device *i2c_dev) |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 512 | { |
| 513 | struct property_entry props[MAX_NO_PROPS] = {}; |
Hans de Goede | 2c37520 | 2018-07-01 20:36:30 +0200 | [diff] [blame] | 514 | int cnt = 0; |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 515 | |
| 516 | props[cnt++] = PROPERTY_ENTRY_U32("realtek,jack-detect-source", |
| 517 | BYT_RT5651_JDSRC(byt_rt5651_quirk)); |
| 518 | |
Hans de Goede | 8ffaa6a | 2018-03-04 15:36:02 +0100 | [diff] [blame] | 519 | props[cnt++] = PROPERTY_ENTRY_U32("realtek,over-current-threshold-microamp", |
| 520 | BYT_RT5651_OVCD_TH(byt_rt5651_quirk) * 100); |
| 521 | |
| 522 | props[cnt++] = PROPERTY_ENTRY_U32("realtek,over-current-scale-factor", |
| 523 | BYT_RT5651_OVCD_SF(byt_rt5651_quirk)); |
| 524 | |
Hans de Goede | c2f2693 | 2018-03-04 15:36:00 +0100 | [diff] [blame] | 525 | if (byt_rt5651_quirk & BYT_RT5651_DMIC_EN) |
| 526 | props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,dmic-en"); |
| 527 | |
Hans de Goede | 2c37520 | 2018-07-01 20:36:30 +0200 | [diff] [blame] | 528 | return device_add_properties(i2c_dev, props); |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 529 | } |
| 530 | |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 531 | static int byt_rt5651_init(struct snd_soc_pcm_runtime *runtime) |
| 532 | { |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 533 | struct snd_soc_card *card = runtime->card; |
Kuninori Morimoto | 17b5201 | 2018-01-29 03:44:39 +0000 | [diff] [blame] | 534 | struct snd_soc_component *codec = runtime->codec_dai->component; |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 535 | struct byt_rt5651_private *priv = snd_soc_card_get_drvdata(card); |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 536 | const struct snd_soc_dapm_route *custom_map; |
| 537 | int num_routes; |
Hans de Goede | 90768ea | 2018-12-30 00:00:24 +0100 | [diff] [blame] | 538 | int report; |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 539 | int ret; |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 540 | |
| 541 | card->dapm.idle_bias_off = true; |
| 542 | |
Hans de Goede | c22969d | 2018-03-04 15:36:10 +0100 | [diff] [blame] | 543 | /* Start with RC clk for jack-detect (we disable MCLK below) */ |
| 544 | if (byt_rt5651_quirk & BYT_RT5651_MCLK_EN) |
| 545 | snd_soc_component_update_bits(codec, RT5651_GLB_CLK, |
| 546 | RT5651_SCLK_SRC_MASK, RT5651_SCLK_SRC_RCCLK); |
| 547 | |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 548 | switch (BYT_RT5651_MAP(byt_rt5651_quirk)) { |
| 549 | case BYT_RT5651_IN1_MAP: |
| 550 | custom_map = byt_rt5651_intmic_in1_map; |
| 551 | num_routes = ARRAY_SIZE(byt_rt5651_intmic_in1_map); |
| 552 | break; |
Hans de Goede | ac275ee | 2018-07-18 22:55:40 +0200 | [diff] [blame] | 553 | case BYT_RT5651_IN2_MAP: |
| 554 | custom_map = byt_rt5651_intmic_in2_map; |
| 555 | num_routes = ARRAY_SIZE(byt_rt5651_intmic_in2_map); |
| 556 | break; |
Carlo Caione | ea261bd | 2017-11-21 17:15:45 +0000 | [diff] [blame] | 557 | case BYT_RT5651_IN1_IN2_MAP: |
| 558 | custom_map = byt_rt5651_intmic_in1_in2_map; |
| 559 | num_routes = ARRAY_SIZE(byt_rt5651_intmic_in1_in2_map); |
| 560 | break; |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 561 | default: |
Pierre-Louis Bossart | 6356c78 | 2017-09-08 12:43:53 -0500 | [diff] [blame] | 562 | custom_map = byt_rt5651_intmic_dmic_map; |
| 563 | num_routes = ARRAY_SIZE(byt_rt5651_intmic_dmic_map); |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 564 | } |
Pierre-Louis Bossart | 6356c78 | 2017-09-08 12:43:53 -0500 | [diff] [blame] | 565 | ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes); |
| 566 | if (ret) |
| 567 | return ret; |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 568 | |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 569 | if (byt_rt5651_quirk & BYT_RT5651_SSP2_AIF2) { |
| 570 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 571 | byt_rt5651_ssp2_aif2_map, |
| 572 | ARRAY_SIZE(byt_rt5651_ssp2_aif2_map)); |
| 573 | } else if (byt_rt5651_quirk & BYT_RT5651_SSP0_AIF1) { |
| 574 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 575 | byt_rt5651_ssp0_aif1_map, |
| 576 | ARRAY_SIZE(byt_rt5651_ssp0_aif1_map)); |
| 577 | } else if (byt_rt5651_quirk & BYT_RT5651_SSP0_AIF2) { |
| 578 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 579 | byt_rt5651_ssp0_aif2_map, |
| 580 | ARRAY_SIZE(byt_rt5651_ssp0_aif2_map)); |
| 581 | } else { |
| 582 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 583 | byt_rt5651_ssp2_aif1_map, |
| 584 | ARRAY_SIZE(byt_rt5651_ssp2_aif1_map)); |
| 585 | } |
| 586 | if (ret) |
| 587 | return ret; |
| 588 | |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 589 | ret = snd_soc_add_card_controls(card, byt_rt5651_controls, |
| 590 | ARRAY_SIZE(byt_rt5651_controls)); |
| 591 | if (ret) { |
| 592 | dev_err(card->dev, "unable to add card controls\n"); |
| 593 | return ret; |
| 594 | } |
| 595 | snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone"); |
| 596 | snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker"); |
| 597 | |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 598 | if (byt_rt5651_quirk & BYT_RT5651_MCLK_EN) { |
| 599 | /* |
| 600 | * The firmware might enable the clock at |
| 601 | * boot (this information may or may not |
| 602 | * be reflected in the enable clock register). |
| 603 | * To change the rate we must disable the clock |
| 604 | * first to cover these cases. Due to common |
| 605 | * clock framework restrictions that do not allow |
| 606 | * to disable a clock that has not been enabled, |
| 607 | * we need to enable the clock first. |
| 608 | */ |
| 609 | ret = clk_prepare_enable(priv->mclk); |
| 610 | if (!ret) |
| 611 | clk_disable_unprepare(priv->mclk); |
| 612 | |
| 613 | if (byt_rt5651_quirk & BYT_RT5651_MCLK_25MHZ) |
| 614 | ret = clk_set_rate(priv->mclk, 25000000); |
| 615 | else |
| 616 | ret = clk_set_rate(priv->mclk, 19200000); |
| 617 | |
| 618 | if (ret) |
| 619 | dev_err(card->dev, "unable to set MCLK rate\n"); |
| 620 | } |
| 621 | |
Hans de Goede | 90768ea | 2018-12-30 00:00:24 +0100 | [diff] [blame] | 622 | report = 0; |
| 623 | if (BYT_RT5651_JDSRC(byt_rt5651_quirk)) |
| 624 | report = SND_JACK_HEADSET | SND_JACK_BTN_0; |
| 625 | else if (priv->hp_detect) |
| 626 | report = SND_JACK_HEADSET; |
| 627 | |
| 628 | if (report) { |
Hans de Goede | aed859a | 2018-03-04 15:36:01 +0100 | [diff] [blame] | 629 | ret = snd_soc_card_jack_new(runtime->card, "Headset", |
Hans de Goede | 90768ea | 2018-12-30 00:00:24 +0100 | [diff] [blame] | 630 | report, &priv->jack, bytcr_jack_pins, |
Hans de Goede | caed9d63 | 2018-07-05 00:59:35 +0200 | [diff] [blame] | 631 | ARRAY_SIZE(bytcr_jack_pins)); |
Hans de Goede | aed859a | 2018-03-04 15:36:01 +0100 | [diff] [blame] | 632 | if (ret) { |
| 633 | dev_err(runtime->dev, "jack creation failed %d\n", ret); |
| 634 | return ret; |
| 635 | } |
| 636 | |
Hans de Goede | 90768ea | 2018-12-30 00:00:24 +0100 | [diff] [blame] | 637 | if (report & SND_JACK_BTN_0) |
| 638 | snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0, |
| 639 | KEY_PLAYPAUSE); |
Hans de Goede | caed9d63 | 2018-07-05 00:59:35 +0200 | [diff] [blame] | 640 | |
Hans de Goede | 90768ea | 2018-12-30 00:00:24 +0100 | [diff] [blame] | 641 | ret = snd_soc_component_set_jack(codec, &priv->jack, |
| 642 | priv->hp_detect); |
Hans de Goede | aed859a | 2018-03-04 15:36:01 +0100 | [diff] [blame] | 643 | if (ret) |
| 644 | return ret; |
Carlo Caione | d9f8f9b | 2017-10-20 12:18:56 +0100 | [diff] [blame] | 645 | } |
| 646 | |
Hans de Goede | aed859a | 2018-03-04 15:36:01 +0100 | [diff] [blame] | 647 | return 0; |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | static const struct snd_soc_pcm_stream byt_rt5651_dai_params = { |
| 651 | .formats = SNDRV_PCM_FMTBIT_S24_LE, |
| 652 | .rate_min = 48000, |
| 653 | .rate_max = 48000, |
| 654 | .channels_min = 2, |
| 655 | .channels_max = 2, |
| 656 | }; |
| 657 | |
| 658 | static int byt_rt5651_codec_fixup(struct snd_soc_pcm_runtime *rtd, |
| 659 | struct snd_pcm_hw_params *params) |
| 660 | { |
| 661 | struct snd_interval *rate = hw_param_interval(params, |
| 662 | SNDRV_PCM_HW_PARAM_RATE); |
| 663 | struct snd_interval *channels = hw_param_interval(params, |
| 664 | SNDRV_PCM_HW_PARAM_CHANNELS); |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 665 | int ret, bits; |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 666 | |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 667 | /* The DSP will covert the FE rate to 48k, stereo */ |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 668 | rate->min = rate->max = 48000; |
| 669 | channels->min = channels->max = 2; |
| 670 | |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 671 | if ((byt_rt5651_quirk & BYT_RT5651_SSP0_AIF1) || |
| 672 | (byt_rt5651_quirk & BYT_RT5651_SSP0_AIF2)) { |
| 673 | /* set SSP0 to 16-bit */ |
| 674 | params_set_format(params, SNDRV_PCM_FORMAT_S16_LE); |
| 675 | bits = 16; |
| 676 | } else { |
| 677 | /* set SSP2 to 24-bit */ |
| 678 | params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); |
| 679 | bits = 24; |
| 680 | } |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 681 | |
| 682 | /* |
| 683 | * Default mode for SSP configuration is TDM 4 slot, override config |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 684 | * with explicit setting to I2S 2ch. The word length is set with |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 685 | * dai_set_tdm_slot() since there is no other API exposed |
| 686 | */ |
| 687 | ret = snd_soc_dai_set_fmt(rtd->cpu_dai, |
| 688 | SND_SOC_DAIFMT_I2S | |
Pierre-Louis Bossart | f12f5c8 | 2017-01-26 14:09:29 -0600 | [diff] [blame] | 689 | SND_SOC_DAIFMT_NB_NF | |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 690 | SND_SOC_DAIFMT_CBS_CFS |
| 691 | ); |
| 692 | |
| 693 | if (ret < 0) { |
| 694 | dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret); |
| 695 | return ret; |
| 696 | } |
| 697 | |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 698 | ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, bits); |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 699 | if (ret < 0) { |
| 700 | dev_err(rtd->dev, "can't set I2S config, err %d\n", ret); |
| 701 | return ret; |
| 702 | } |
| 703 | |
| 704 | return 0; |
| 705 | } |
| 706 | |
Takashi Iwai | 1ebb4d9 | 2017-06-08 23:37:22 +0200 | [diff] [blame] | 707 | static const unsigned int rates_48000[] = { |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 708 | 48000, |
| 709 | }; |
| 710 | |
Takashi Iwai | 1ebb4d9 | 2017-06-08 23:37:22 +0200 | [diff] [blame] | 711 | static const struct snd_pcm_hw_constraint_list constraints_48000 = { |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 712 | .count = ARRAY_SIZE(rates_48000), |
| 713 | .list = rates_48000, |
| 714 | }; |
| 715 | |
| 716 | static int byt_rt5651_aif1_startup(struct snd_pcm_substream *substream) |
| 717 | { |
| 718 | return snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 719 | SNDRV_PCM_HW_PARAM_RATE, |
| 720 | &constraints_48000); |
| 721 | } |
| 722 | |
Julia Lawall | 9b6fdef | 2016-10-15 16:55:49 +0200 | [diff] [blame] | 723 | static const struct snd_soc_ops byt_rt5651_aif1_ops = { |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 724 | .startup = byt_rt5651_aif1_startup, |
| 725 | }; |
| 726 | |
Julia Lawall | 9b6fdef | 2016-10-15 16:55:49 +0200 | [diff] [blame] | 727 | static const struct snd_soc_ops byt_rt5651_be_ssp2_ops = { |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 728 | .hw_params = byt_rt5651_aif1_hw_params, |
| 729 | }; |
| 730 | |
| 731 | static struct snd_soc_dai_link byt_rt5651_dais[] = { |
| 732 | [MERR_DPCM_AUDIO] = { |
| 733 | .name = "Audio Port", |
| 734 | .stream_name = "Audio", |
| 735 | .cpu_dai_name = "media-cpu-dai", |
| 736 | .codec_dai_name = "snd-soc-dummy-dai", |
| 737 | .codec_name = "snd-soc-dummy", |
| 738 | .platform_name = "sst-mfld-platform", |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 739 | .nonatomic = true, |
| 740 | .dynamic = 1, |
| 741 | .dpcm_playback = 1, |
| 742 | .dpcm_capture = 1, |
| 743 | .ops = &byt_rt5651_aif1_ops, |
| 744 | }, |
| 745 | [MERR_DPCM_DEEP_BUFFER] = { |
| 746 | .name = "Deep-Buffer Audio Port", |
| 747 | .stream_name = "Deep-Buffer Audio", |
| 748 | .cpu_dai_name = "deepbuffer-cpu-dai", |
| 749 | .codec_dai_name = "snd-soc-dummy-dai", |
| 750 | .codec_name = "snd-soc-dummy", |
| 751 | .platform_name = "sst-mfld-platform", |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 752 | .nonatomic = true, |
| 753 | .dynamic = 1, |
| 754 | .dpcm_playback = 1, |
| 755 | .ops = &byt_rt5651_aif1_ops, |
| 756 | }, |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 757 | /* CODEC<->CODEC link */ |
| 758 | /* back ends */ |
| 759 | { |
| 760 | .name = "SSP2-Codec", |
Pierre-Louis Bossart | 149f775 | 2017-10-12 18:38:04 -0500 | [diff] [blame] | 761 | .id = 0, |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 762 | .cpu_dai_name = "ssp2-port", |
| 763 | .platform_name = "sst-mfld-platform", |
| 764 | .no_pcm = 1, |
| 765 | .codec_dai_name = "rt5651-aif1", |
| 766 | .codec_name = "i2c-10EC5651:00", |
| 767 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 768 | | SND_SOC_DAIFMT_CBS_CFS, |
| 769 | .be_hw_params_fixup = byt_rt5651_codec_fixup, |
| 770 | .ignore_suspend = 1, |
| 771 | .nonatomic = true, |
| 772 | .dpcm_playback = 1, |
| 773 | .dpcm_capture = 1, |
| 774 | .init = byt_rt5651_init, |
| 775 | .ops = &byt_rt5651_be_ssp2_ops, |
| 776 | }, |
| 777 | }; |
| 778 | |
| 779 | /* SoC card */ |
Hans de Goede | b91f432 | 2018-07-05 00:59:34 +0200 | [diff] [blame] | 780 | static char byt_rt5651_codec_name[SND_ACPI_I2C_ID_LEN]; |
| 781 | static char byt_rt5651_codec_aif_name[12]; /* = "rt5651-aif[1|2]" */ |
| 782 | static char byt_rt5651_cpu_dai_name[10]; /* = "ssp[0|2]-port" */ |
Hans de Goede | a0d1d86 | 2018-07-18 22:55:41 +0200 | [diff] [blame] | 783 | static char byt_rt5651_long_name[50]; /* = "bytcr-rt5651-*-spk-*-mic[-swapped-hp]" */ |
Hans de Goede | b91f432 | 2018-07-05 00:59:34 +0200 | [diff] [blame] | 784 | |
| 785 | static int byt_rt5651_suspend(struct snd_soc_card *card) |
| 786 | { |
| 787 | struct snd_soc_component *component; |
| 788 | |
| 789 | if (!BYT_RT5651_JDSRC(byt_rt5651_quirk)) |
| 790 | return 0; |
| 791 | |
Kuninori Morimoto | f70f18f7 | 2018-09-18 01:29:55 +0000 | [diff] [blame] | 792 | for_each_card_components(card, component) { |
Hans de Goede | b91f432 | 2018-07-05 00:59:34 +0200 | [diff] [blame] | 793 | if (!strcmp(component->name, byt_rt5651_codec_name)) { |
| 794 | dev_dbg(component->dev, "disabling jack detect before suspend\n"); |
| 795 | snd_soc_component_set_jack(component, NULL, NULL); |
| 796 | break; |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | static int byt_rt5651_resume(struct snd_soc_card *card) |
| 804 | { |
| 805 | struct byt_rt5651_private *priv = snd_soc_card_get_drvdata(card); |
| 806 | struct snd_soc_component *component; |
| 807 | |
| 808 | if (!BYT_RT5651_JDSRC(byt_rt5651_quirk)) |
| 809 | return 0; |
| 810 | |
Kuninori Morimoto | f70f18f7 | 2018-09-18 01:29:55 +0000 | [diff] [blame] | 811 | for_each_card_components(card, component) { |
Hans de Goede | b91f432 | 2018-07-05 00:59:34 +0200 | [diff] [blame] | 812 | if (!strcmp(component->name, byt_rt5651_codec_name)) { |
| 813 | dev_dbg(component->dev, "re-enabling jack detect after resume\n"); |
Hans de Goede | 90768ea | 2018-12-30 00:00:24 +0100 | [diff] [blame] | 814 | snd_soc_component_set_jack(component, &priv->jack, |
| 815 | priv->hp_detect); |
Hans de Goede | b91f432 | 2018-07-05 00:59:34 +0200 | [diff] [blame] | 816 | break; |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | return 0; |
| 821 | } |
| 822 | |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 823 | static struct snd_soc_card byt_rt5651_card = { |
| 824 | .name = "bytcr-rt5651", |
| 825 | .owner = THIS_MODULE, |
| 826 | .dai_link = byt_rt5651_dais, |
| 827 | .num_links = ARRAY_SIZE(byt_rt5651_dais), |
| 828 | .dapm_widgets = byt_rt5651_widgets, |
| 829 | .num_dapm_widgets = ARRAY_SIZE(byt_rt5651_widgets), |
| 830 | .dapm_routes = byt_rt5651_audio_map, |
| 831 | .num_dapm_routes = ARRAY_SIZE(byt_rt5651_audio_map), |
| 832 | .fully_routed = true, |
Hans de Goede | b91f432 | 2018-07-05 00:59:34 +0200 | [diff] [blame] | 833 | .suspend_pre = byt_rt5651_suspend, |
| 834 | .resume_post = byt_rt5651_resume, |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 835 | }; |
| 836 | |
Hans de Goede | fbea16d | 2018-07-01 20:36:29 +0200 | [diff] [blame] | 837 | static const struct x86_cpu_id baytrail_cpu_ids[] = { |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 838 | { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT }, /* Valleyview */ |
Hans de Goede | fbea16d | 2018-07-01 20:36:29 +0200 | [diff] [blame] | 839 | {} |
| 840 | }; |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 841 | |
Hans de Goede | 5f6fb23 | 2018-07-01 20:36:31 +0200 | [diff] [blame] | 842 | static const struct x86_cpu_id cherrytrail_cpu_ids[] = { |
| 843 | { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_AIRMONT }, /* Braswell */ |
| 844 | {} |
| 845 | }; |
| 846 | |
Andy Shevchenko | 4d1f7a6 | 2019-02-06 22:49:46 +0200 | [diff] [blame^] | 847 | static const struct acpi_gpio_params ext_amp_enable_gpios = { 0, 0, false }; |
Hans de Goede | 5f6fb23 | 2018-07-01 20:36:31 +0200 | [diff] [blame] | 848 | |
Andy Shevchenko | 4d1f7a6 | 2019-02-06 22:49:46 +0200 | [diff] [blame^] | 849 | static const struct acpi_gpio_mapping cht_rt5651_gpios[] = { |
| 850 | /* |
| 851 | * Some boards have I2cSerialBusV2, GpioIo, GpioInt as ACPI resources, |
| 852 | * other boards may have I2cSerialBusV2, GpioInt, GpioIo instead. |
| 853 | * We want the GpioIo one for the ext-amp-enable-gpio. |
| 854 | */ |
| 855 | { "ext-amp-enable-gpios", &ext_amp_enable_gpios, 1, ACPI_GPIO_QUIRK_ONLY_GPIOIO }, |
Hans de Goede | 5f6fb23 | 2018-07-01 20:36:31 +0200 | [diff] [blame] | 856 | { }, |
| 857 | }; |
| 858 | |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 859 | struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */ |
| 860 | u64 aif_value; /* 1: AIF1, 2: AIF2 */ |
| 861 | u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */ |
| 862 | }; |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 863 | |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 864 | static int snd_byt_rt5651_mc_probe(struct platform_device *pdev) |
| 865 | { |
Colin Ian King | 4ffdca6 | 2019-01-24 17:37:35 +0000 | [diff] [blame] | 866 | static const char * const mic_name[] = { "dmic", "in1", "in2", "in12" }; |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 867 | struct byt_rt5651_private *priv; |
Pierre-Louis Bossart | 7feb2f7 | 2017-10-12 18:49:38 -0500 | [diff] [blame] | 868 | struct snd_soc_acpi_mach *mach; |
Pierre-Louis Bossart | 0b2c209 | 2019-01-25 14:35:00 -0600 | [diff] [blame] | 869 | const char *platform_name; |
Hans de Goede | 2c37520 | 2018-07-01 20:36:30 +0200 | [diff] [blame] | 870 | struct device *codec_dev; |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 871 | const char *i2c_name = NULL; |
Hans de Goede | 8f250e7 | 2018-06-24 16:06:33 +0200 | [diff] [blame] | 872 | const char *hp_swapped; |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 873 | bool is_bytcr = false; |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 874 | int ret_val = 0; |
Pierre-Louis Bossart | 2193eb9 | 2017-10-12 18:38:05 -0500 | [diff] [blame] | 875 | int dai_index = 0; |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 876 | int i; |
| 877 | |
Vinod Koul | aa5398e | 2018-04-20 16:14:28 +0530 | [diff] [blame] | 878 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 879 | if (!priv) |
| 880 | return -ENOMEM; |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 881 | |
| 882 | /* register the soc card */ |
| 883 | byt_rt5651_card.dev = &pdev->dev; |
| 884 | |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 885 | mach = byt_rt5651_card.dev->platform_data; |
| 886 | snd_soc_card_set_drvdata(&byt_rt5651_card, priv); |
| 887 | |
| 888 | /* fix index of codec dai */ |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 889 | for (i = 0; i < ARRAY_SIZE(byt_rt5651_dais); i++) { |
| 890 | if (!strcmp(byt_rt5651_dais[i].codec_name, "i2c-10EC5651:00")) { |
| 891 | dai_index = i; |
| 892 | break; |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | /* fixup codec name based on HID */ |
Andy Shevchenko | 3a14795 | 2018-01-12 23:16:17 +0200 | [diff] [blame] | 897 | i2c_name = acpi_dev_get_first_match_name(mach->id, NULL, -1); |
Hans de Goede | e39cacc | 2018-03-04 15:35:58 +0100 | [diff] [blame] | 898 | if (!i2c_name) { |
| 899 | dev_err(&pdev->dev, "Error cannot find '%s' dev\n", mach->id); |
| 900 | return -ENODEV; |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 901 | } |
Hans de Goede | e39cacc | 2018-03-04 15:35:58 +0100 | [diff] [blame] | 902 | snprintf(byt_rt5651_codec_name, sizeof(byt_rt5651_codec_name), |
| 903 | "%s%s", "i2c-", i2c_name); |
| 904 | byt_rt5651_dais[dai_index].codec_name = byt_rt5651_codec_name; |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 905 | |
Hans de Goede | 2c37520 | 2018-07-01 20:36:30 +0200 | [diff] [blame] | 906 | codec_dev = bus_find_device_by_name(&i2c_bus_type, NULL, |
| 907 | byt_rt5651_codec_name); |
| 908 | if (!codec_dev) |
| 909 | return -EPROBE_DEFER; |
| 910 | |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 911 | /* |
| 912 | * swap SSP0 if bytcr is detected |
| 913 | * (will be overridden if DMI quirk is detected) |
| 914 | */ |
Hans de Goede | fbea16d | 2018-07-01 20:36:29 +0200 | [diff] [blame] | 915 | if (x86_match_cpu(baytrail_cpu_ids)) { |
Pierre-Louis Bossart | 3ee1cd4 | 2018-11-01 16:34:50 -0500 | [diff] [blame] | 916 | if (mach->mach_params.acpi_ipc_irq_index == 0) |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 917 | is_bytcr = true; |
| 918 | } |
| 919 | |
| 920 | if (is_bytcr) { |
| 921 | /* |
| 922 | * Baytrail CR platforms may have CHAN package in BIOS, try |
| 923 | * to find relevant routing quirk based as done on Windows |
| 924 | * platforms. We have to read the information directly from the |
| 925 | * BIOS, at this stage the card is not created and the links |
| 926 | * with the codec driver/pdata are non-existent |
| 927 | */ |
| 928 | |
| 929 | struct acpi_chan_package chan_package; |
| 930 | |
| 931 | /* format specified: 2 64-bit integers */ |
| 932 | struct acpi_buffer format = {sizeof("NN"), "NN"}; |
| 933 | struct acpi_buffer state = {0, NULL}; |
| 934 | struct snd_soc_acpi_package_context pkg_ctx; |
| 935 | bool pkg_found = false; |
| 936 | |
| 937 | state.length = sizeof(chan_package); |
| 938 | state.pointer = &chan_package; |
| 939 | |
| 940 | pkg_ctx.name = "CHAN"; |
| 941 | pkg_ctx.length = 2; |
| 942 | pkg_ctx.format = &format; |
| 943 | pkg_ctx.state = &state; |
| 944 | pkg_ctx.data_valid = false; |
| 945 | |
| 946 | pkg_found = snd_soc_acpi_find_package_from_hid(mach->id, |
| 947 | &pkg_ctx); |
| 948 | if (pkg_found) { |
| 949 | if (chan_package.aif_value == 1) { |
| 950 | dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n"); |
| 951 | byt_rt5651_quirk |= BYT_RT5651_SSP0_AIF1; |
| 952 | } else if (chan_package.aif_value == 2) { |
| 953 | dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n"); |
| 954 | byt_rt5651_quirk |= BYT_RT5651_SSP0_AIF2; |
| 955 | } else { |
| 956 | dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n"); |
| 957 | pkg_found = false; |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | if (!pkg_found) { |
| 962 | /* no BIOS indications, assume SSP0-AIF2 connection */ |
| 963 | byt_rt5651_quirk |= BYT_RT5651_SSP0_AIF2; |
| 964 | } |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 965 | } |
| 966 | |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 967 | /* check quirks before creating card */ |
| 968 | dmi_check_system(byt_rt5651_quirk_table); |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 969 | |
Hans de Goede | 7eb1873 | 2018-12-30 00:00:23 +0100 | [diff] [blame] | 970 | if (quirk_override) { |
| 971 | dev_info(&pdev->dev, "Overriding quirk 0x%x => 0x%x\n", |
| 972 | (unsigned int)byt_rt5651_quirk, quirk_override); |
| 973 | byt_rt5651_quirk = quirk_override; |
| 974 | } |
| 975 | |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 976 | /* Must be called before register_card, also see declaration comment. */ |
Hans de Goede | 2c37520 | 2018-07-01 20:36:30 +0200 | [diff] [blame] | 977 | ret_val = byt_rt5651_add_codec_device_props(codec_dev); |
Hans de Goede | 5f6fb23 | 2018-07-01 20:36:31 +0200 | [diff] [blame] | 978 | if (ret_val) { |
| 979 | put_device(codec_dev); |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 980 | return ret_val; |
Hans de Goede | 5f6fb23 | 2018-07-01 20:36:31 +0200 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | /* Cherry Trail devices use an external amplifier enable gpio */ |
Hans de Goede | fee3e1c | 2018-12-30 00:00:25 +0100 | [diff] [blame] | 984 | if (x86_match_cpu(cherrytrail_cpu_ids) && !byt_rt5651_gpios) |
Andy Shevchenko | 4d1f7a6 | 2019-02-06 22:49:46 +0200 | [diff] [blame^] | 985 | byt_rt5651_gpios = cht_rt5651_gpios; |
Hans de Goede | fee3e1c | 2018-12-30 00:00:25 +0100 | [diff] [blame] | 986 | |
| 987 | if (byt_rt5651_gpios) { |
| 988 | devm_acpi_dev_add_driver_gpios(codec_dev, byt_rt5651_gpios); |
Hans de Goede | 5f6fb23 | 2018-07-01 20:36:31 +0200 | [diff] [blame] | 989 | priv->ext_amp_gpio = devm_fwnode_get_index_gpiod_from_child( |
| 990 | &pdev->dev, "ext-amp-enable", 0, |
| 991 | codec_dev->fwnode, |
| 992 | GPIOD_OUT_LOW, "speaker-amp"); |
| 993 | if (IS_ERR(priv->ext_amp_gpio)) { |
| 994 | ret_val = PTR_ERR(priv->ext_amp_gpio); |
| 995 | switch (ret_val) { |
| 996 | case -ENOENT: |
| 997 | priv->ext_amp_gpio = NULL; |
| 998 | break; |
| 999 | default: |
| 1000 | dev_err(&pdev->dev, "Failed to get ext-amp-enable GPIO: %d\n", |
| 1001 | ret_val); |
| 1002 | /* fall through */ |
| 1003 | case -EPROBE_DEFER: |
| 1004 | put_device(codec_dev); |
| 1005 | return ret_val; |
| 1006 | } |
| 1007 | } |
Hans de Goede | 90768ea | 2018-12-30 00:00:24 +0100 | [diff] [blame] | 1008 | priv->hp_detect = devm_fwnode_get_index_gpiod_from_child( |
| 1009 | &pdev->dev, "hp-detect", 0, |
| 1010 | codec_dev->fwnode, |
| 1011 | GPIOD_IN, "hp-detect"); |
| 1012 | if (IS_ERR(priv->hp_detect)) { |
| 1013 | ret_val = PTR_ERR(priv->hp_detect); |
| 1014 | switch (ret_val) { |
| 1015 | case -ENOENT: |
| 1016 | priv->hp_detect = NULL; |
| 1017 | break; |
| 1018 | default: |
| 1019 | dev_err(&pdev->dev, "Failed to get hp-detect GPIO: %d\n", |
| 1020 | ret_val); |
| 1021 | /* fall through */ |
| 1022 | case -EPROBE_DEFER: |
| 1023 | put_device(codec_dev); |
| 1024 | return ret_val; |
| 1025 | } |
| 1026 | } |
Hans de Goede | 5f6fb23 | 2018-07-01 20:36:31 +0200 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | put_device(codec_dev); |
Hans de Goede | 46058ae | 2018-03-04 15:35:59 +0100 | [diff] [blame] | 1030 | |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 1031 | log_quirks(&pdev->dev); |
| 1032 | |
Hans de Goede | 8a880a2 | 2018-03-04 15:36:07 +0100 | [diff] [blame] | 1033 | if ((byt_rt5651_quirk & BYT_RT5651_SSP2_AIF2) || |
| 1034 | (byt_rt5651_quirk & BYT_RT5651_SSP0_AIF2)) { |
| 1035 | /* fixup codec aif name */ |
| 1036 | snprintf(byt_rt5651_codec_aif_name, |
| 1037 | sizeof(byt_rt5651_codec_aif_name), |
| 1038 | "%s", "rt5651-aif2"); |
| 1039 | |
| 1040 | byt_rt5651_dais[dai_index].codec_dai_name = |
| 1041 | byt_rt5651_codec_aif_name; |
| 1042 | } |
| 1043 | |
| 1044 | if ((byt_rt5651_quirk & BYT_RT5651_SSP0_AIF1) || |
| 1045 | (byt_rt5651_quirk & BYT_RT5651_SSP0_AIF2)) { |
| 1046 | /* fixup cpu dai name name */ |
| 1047 | snprintf(byt_rt5651_cpu_dai_name, |
| 1048 | sizeof(byt_rt5651_cpu_dai_name), |
| 1049 | "%s", "ssp0-port"); |
| 1050 | |
| 1051 | byt_rt5651_dais[dai_index].cpu_dai_name = |
| 1052 | byt_rt5651_cpu_dai_name; |
| 1053 | } |
| 1054 | |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 1055 | if (byt_rt5651_quirk & BYT_RT5651_MCLK_EN) { |
| 1056 | priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3"); |
| 1057 | if (IS_ERR(priv->mclk)) { |
Colin Ian King | de5afce | 2018-05-02 15:29:45 +0100 | [diff] [blame] | 1058 | ret_val = PTR_ERR(priv->mclk); |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 1059 | dev_err(&pdev->dev, |
Colin Ian King | de5afce | 2018-05-02 15:29:45 +0100 | [diff] [blame] | 1060 | "Failed to get MCLK from pmc_plt_clk_3: %d\n", |
| 1061 | ret_val); |
Pierre-Louis Bossart | 02c0a3b | 2017-10-12 18:37:57 -0500 | [diff] [blame] | 1062 | /* |
| 1063 | * Fall back to bit clock usage for -ENOENT (clock not |
| 1064 | * available likely due to missing dependencies), bail |
| 1065 | * for all other errors, including -EPROBE_DEFER |
| 1066 | */ |
| 1067 | if (ret_val != -ENOENT) |
| 1068 | return ret_val; |
| 1069 | byt_rt5651_quirk &= ~BYT_RT5651_MCLK_EN; |
| 1070 | } |
| 1071 | } |
| 1072 | |
Hans de Goede | 8f250e7 | 2018-06-24 16:06:33 +0200 | [diff] [blame] | 1073 | if (byt_rt5651_quirk & BYT_RT5651_HP_LR_SWAPPED) |
| 1074 | hp_swapped = "-hp-swapped"; |
| 1075 | else |
| 1076 | hp_swapped = ""; |
| 1077 | |
Hans de Goede | 64484cc | 2018-05-18 21:35:06 +0200 | [diff] [blame] | 1078 | snprintf(byt_rt5651_long_name, sizeof(byt_rt5651_long_name), |
Hans de Goede | a0d1d86 | 2018-07-18 22:55:41 +0200 | [diff] [blame] | 1079 | "bytcr-rt5651-%s-spk-%s-mic%s", |
| 1080 | (byt_rt5651_quirk & BYT_RT5651_MONO_SPEAKER) ? |
| 1081 | "mono" : "stereo", |
Hans de Goede | 8f250e7 | 2018-06-24 16:06:33 +0200 | [diff] [blame] | 1082 | mic_name[BYT_RT5651_MAP(byt_rt5651_quirk)], hp_swapped); |
Hans de Goede | 64484cc | 2018-05-18 21:35:06 +0200 | [diff] [blame] | 1083 | byt_rt5651_card.long_name = byt_rt5651_long_name; |
| 1084 | |
Pierre-Louis Bossart | 0b2c209 | 2019-01-25 14:35:00 -0600 | [diff] [blame] | 1085 | /* override plaform name, if required */ |
| 1086 | platform_name = mach->mach_params.platform; |
| 1087 | |
| 1088 | ret_val = snd_soc_fixup_dai_links_platform_name(&byt_rt5651_card, |
| 1089 | platform_name); |
| 1090 | if (ret_val) |
| 1091 | return ret_val; |
| 1092 | |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 1093 | ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5651_card); |
| 1094 | |
| 1095 | if (ret_val) { |
| 1096 | dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n", |
| 1097 | ret_val); |
| 1098 | return ret_val; |
| 1099 | } |
| 1100 | platform_set_drvdata(pdev, &byt_rt5651_card); |
| 1101 | return ret_val; |
| 1102 | } |
| 1103 | |
| 1104 | static struct platform_driver snd_byt_rt5651_mc_driver = { |
| 1105 | .driver = { |
| 1106 | .name = "bytcr_rt5651", |
Pierre-Louis Bossart | 2bd5bd1 | 2016-01-04 17:20:24 -0600 | [diff] [blame] | 1107 | }, |
| 1108 | .probe = snd_byt_rt5651_mc_probe, |
| 1109 | }; |
| 1110 | |
| 1111 | module_platform_driver(snd_byt_rt5651_mc_driver); |
| 1112 | |
| 1113 | MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver for RT5651"); |
| 1114 | MODULE_AUTHOR("Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>"); |
| 1115 | MODULE_LICENSE("GPL v2"); |
| 1116 | MODULE_ALIAS("platform:bytcr_rt5651"); |