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