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