Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 1 | /* |
| 2 | * byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform |
| 3 | * |
| 4 | * Copyright (C) 2014 Intel Corp |
| 5 | * Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com> |
| 6 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 18 | */ |
| 19 | |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/module.h> |
Takashi Iwai | 9f2cf73 | 2017-04-23 09:22:56 +0200 | [diff] [blame^] | 22 | #include <linux/moduleparam.h> |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 24 | #include <linux/acpi.h> |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 25 | #include <linux/device.h> |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 26 | #include <linux/dmi.h> |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 27 | #include <linux/slab.h> |
Pierre-Louis Bossart | e214f5e | 2016-08-12 16:27:53 -0500 | [diff] [blame] | 28 | #include <asm/cpu_device_id.h> |
| 29 | #include <asm/platform_sst_audio.h> |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 30 | #include <linux/clk.h> |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 31 | #include <sound/pcm.h> |
| 32 | #include <sound/pcm_params.h> |
| 33 | #include <sound/soc.h> |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 34 | #include <sound/jack.h> |
Jie Yang | e56c72d | 2015-04-02 15:37:02 +0800 | [diff] [blame] | 35 | #include "../../codecs/rt5640.h" |
Jie Yang | b97169d | 2015-04-02 15:37:04 +0800 | [diff] [blame] | 36 | #include "../atom/sst-atom-controls.h" |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 37 | #include "../common/sst-acpi.h" |
Pierre-Louis Bossart | e214f5e | 2016-08-12 16:27:53 -0500 | [diff] [blame] | 38 | #include "../common/sst-dsp.h" |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 39 | |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 40 | enum { |
| 41 | BYT_RT5640_DMIC1_MAP, |
| 42 | BYT_RT5640_DMIC2_MAP, |
| 43 | BYT_RT5640_IN1_MAP, |
Pierre-Louis Bossart | 59e8b65 | 2016-08-12 16:27:54 -0500 | [diff] [blame] | 44 | BYT_RT5640_IN3_MAP, |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | #define BYT_RT5640_MAP(quirk) ((quirk) & 0xff) |
| 48 | #define BYT_RT5640_DMIC_EN BIT(16) |
Pierre-Louis Bossart | 68817cd | 2016-08-12 16:27:45 -0500 | [diff] [blame] | 49 | #define BYT_RT5640_MONO_SPEAKER BIT(17) |
Pierre-Louis Bossart | 5d98f58 | 2016-08-12 16:27:46 -0500 | [diff] [blame] | 50 | #define BYT_RT5640_DIFF_MIC BIT(18) /* defaut is single-ended */ |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame] | 51 | #define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */ |
Pierre-Louis Bossart | f47088d | 2016-08-12 16:27:51 -0500 | [diff] [blame] | 52 | #define BYT_RT5640_SSP0_AIF1 BIT(20) |
| 53 | #define BYT_RT5640_SSP0_AIF2 BIT(21) |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 54 | #define BYT_RT5640_MCLK_EN BIT(22) |
| 55 | #define BYT_RT5640_MCLK_25MHZ BIT(23) |
| 56 | |
| 57 | struct byt_rt5640_private { |
| 58 | struct clk *mclk; |
| 59 | }; |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 60 | |
Pierre-Louis Bossart | bf46241 | 2016-11-12 18:07:46 -0600 | [diff] [blame] | 61 | static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN; |
Takashi Iwai | 9f2cf73 | 2017-04-23 09:22:56 +0200 | [diff] [blame^] | 62 | static unsigned int quirk_override; |
| 63 | module_param_named(quirk, quirk_override, int, 0444); |
| 64 | MODULE_PARM_DESC(quirk, "Board-specific quirk override"); |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 65 | |
Pierre-Louis Bossart | d7e60d5 | 2016-08-12 16:28:00 -0500 | [diff] [blame] | 66 | static void log_quirks(struct device *dev) |
| 67 | { |
| 68 | if (BYT_RT5640_MAP(byt_rt5640_quirk) == BYT_RT5640_DMIC1_MAP) |
| 69 | dev_info(dev, "quirk DMIC1_MAP enabled"); |
| 70 | if (BYT_RT5640_MAP(byt_rt5640_quirk) == BYT_RT5640_DMIC2_MAP) |
| 71 | dev_info(dev, "quirk DMIC2_MAP enabled"); |
| 72 | if (BYT_RT5640_MAP(byt_rt5640_quirk) == BYT_RT5640_IN1_MAP) |
| 73 | dev_info(dev, "quirk IN1_MAP enabled"); |
| 74 | if (BYT_RT5640_MAP(byt_rt5640_quirk) == BYT_RT5640_IN3_MAP) |
| 75 | dev_info(dev, "quirk IN3_MAP enabled"); |
| 76 | if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN) |
| 77 | dev_info(dev, "quirk DMIC enabled"); |
| 78 | if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) |
| 79 | dev_info(dev, "quirk MONO_SPEAKER enabled"); |
| 80 | if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC) |
| 81 | dev_info(dev, "quirk DIFF_MIC enabled"); |
| 82 | if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) |
| 83 | dev_info(dev, "quirk SSP2_AIF2 enabled"); |
| 84 | if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) |
| 85 | dev_info(dev, "quirk SSP0_AIF1 enabled"); |
| 86 | if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) |
| 87 | dev_info(dev, "quirk SSP0_AIF2 enabled"); |
| 88 | if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) |
| 89 | dev_info(dev, "quirk MCLK_EN enabled"); |
| 90 | if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) |
| 91 | dev_info(dev, "quirk MCLK_25MHZ enabled"); |
| 92 | } |
| 93 | |
| 94 | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 95 | #define BYT_CODEC_DAI1 "rt5640-aif1" |
| 96 | #define BYT_CODEC_DAI2 "rt5640-aif2" |
| 97 | |
| 98 | static inline struct snd_soc_dai *byt_get_codec_dai(struct snd_soc_card *card) |
| 99 | { |
| 100 | struct snd_soc_pcm_runtime *rtd; |
| 101 | |
| 102 | list_for_each_entry(rtd, &card->rtd_list, list) { |
| 103 | if (!strncmp(rtd->codec_dai->name, BYT_CODEC_DAI1, |
| 104 | strlen(BYT_CODEC_DAI1))) |
| 105 | return rtd->codec_dai; |
| 106 | if (!strncmp(rtd->codec_dai->name, BYT_CODEC_DAI2, |
| 107 | strlen(BYT_CODEC_DAI2))) |
| 108 | return rtd->codec_dai; |
| 109 | |
| 110 | } |
| 111 | return NULL; |
| 112 | } |
| 113 | |
| 114 | static int platform_clock_control(struct snd_soc_dapm_widget *w, |
| 115 | struct snd_kcontrol *k, int event) |
| 116 | { |
| 117 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 118 | struct snd_soc_card *card = dapm->card; |
| 119 | struct snd_soc_dai *codec_dai; |
| 120 | struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card); |
| 121 | int ret; |
| 122 | |
| 123 | codec_dai = byt_get_codec_dai(card); |
| 124 | if (!codec_dai) { |
| 125 | dev_err(card->dev, |
| 126 | "Codec dai not found; Unable to set platform clock\n"); |
| 127 | return -EIO; |
| 128 | } |
| 129 | |
| 130 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
| 131 | if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && priv->mclk) { |
| 132 | ret = clk_prepare_enable(priv->mclk); |
| 133 | if (ret < 0) { |
| 134 | dev_err(card->dev, |
| 135 | "could not configure MCLK state"); |
| 136 | return ret; |
| 137 | } |
| 138 | } |
| 139 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1, |
| 140 | 48000 * 512, |
| 141 | SND_SOC_CLOCK_IN); |
| 142 | } else { |
| 143 | /* |
| 144 | * Set codec clock source to internal clock before |
| 145 | * turning off the platform clock. Codec needs clock |
| 146 | * for Jack detection and button press |
| 147 | */ |
| 148 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK, |
Pierre-Louis Bossart | 60448b0 | 2017-01-04 15:44:52 -0600 | [diff] [blame] | 149 | 48000 * 512, |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 150 | SND_SOC_CLOCK_IN); |
| 151 | if (!ret) { |
| 152 | if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && priv->mclk) |
| 153 | clk_disable_unprepare(priv->mclk); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | if (ret < 0) { |
| 158 | dev_err(card->dev, "can't set codec sysclk: %d\n", ret); |
| 159 | return ret; |
| 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 164 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 165 | static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 166 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 167 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
Pierre-Louis Bossart | e2be1da | 2015-12-17 20:35:40 -0600 | [diff] [blame] | 168 | SND_SOC_DAPM_MIC("Internal Mic", NULL), |
| 169 | SND_SOC_DAPM_SPK("Speaker", NULL), |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 170 | SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, |
| 171 | platform_clock_control, SND_SOC_DAPM_PRE_PMU | |
| 172 | SND_SOC_DAPM_POST_PMD), |
| 173 | |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 174 | }; |
| 175 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 176 | static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = { |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 177 | {"Headphone", NULL, "Platform Clock"}, |
| 178 | {"Headset Mic", NULL, "Platform Clock"}, |
| 179 | {"Internal Mic", NULL, "Platform Clock"}, |
| 180 | {"Speaker", NULL, "Platform Clock"}, |
| 181 | |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 182 | {"Headset Mic", NULL, "MICBIAS1"}, |
Pierre-Louis Bossart | e2be1da | 2015-12-17 20:35:40 -0600 | [diff] [blame] | 183 | {"IN2P", NULL, "Headset Mic"}, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 184 | {"Headphone", NULL, "HPOL"}, |
| 185 | {"Headphone", NULL, "HPOR"}, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 186 | }; |
| 187 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 188 | static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = { |
| 189 | {"DMIC1", NULL, "Internal Mic"}, |
| 190 | }; |
| 191 | |
| 192 | static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = { |
| 193 | {"DMIC2", NULL, "Internal Mic"}, |
| 194 | }; |
| 195 | |
| 196 | static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = { |
| 197 | {"Internal Mic", NULL, "MICBIAS1"}, |
| 198 | {"IN1P", NULL, "Internal Mic"}, |
| 199 | }; |
| 200 | |
Pierre-Louis Bossart | 59e8b65 | 2016-08-12 16:27:54 -0500 | [diff] [blame] | 201 | static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = { |
| 202 | {"Internal Mic", NULL, "MICBIAS1"}, |
| 203 | {"IN3P", NULL, "Internal Mic"}, |
| 204 | }; |
| 205 | |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame] | 206 | static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = { |
| 207 | {"ssp2 Tx", NULL, "codec_out0"}, |
| 208 | {"ssp2 Tx", NULL, "codec_out1"}, |
| 209 | {"codec_in0", NULL, "ssp2 Rx"}, |
| 210 | {"codec_in1", NULL, "ssp2 Rx"}, |
| 211 | |
| 212 | {"AIF1 Playback", NULL, "ssp2 Tx"}, |
| 213 | {"ssp2 Rx", NULL, "AIF1 Capture"}, |
| 214 | }; |
| 215 | |
| 216 | static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = { |
| 217 | {"ssp2 Tx", NULL, "codec_out0"}, |
| 218 | {"ssp2 Tx", NULL, "codec_out1"}, |
| 219 | {"codec_in0", NULL, "ssp2 Rx"}, |
| 220 | {"codec_in1", NULL, "ssp2 Rx"}, |
| 221 | |
| 222 | {"AIF2 Playback", NULL, "ssp2 Tx"}, |
| 223 | {"ssp2 Rx", NULL, "AIF2 Capture"}, |
| 224 | }; |
| 225 | |
Pierre-Louis Bossart | f47088d | 2016-08-12 16:27:51 -0500 | [diff] [blame] | 226 | static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = { |
| 227 | {"ssp0 Tx", NULL, "modem_out"}, |
| 228 | {"modem_in", NULL, "ssp0 Rx"}, |
| 229 | |
| 230 | {"AIF1 Playback", NULL, "ssp0 Tx"}, |
| 231 | {"ssp0 Rx", NULL, "AIF1 Capture"}, |
| 232 | }; |
| 233 | |
| 234 | static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = { |
| 235 | {"ssp0 Tx", NULL, "modem_out"}, |
| 236 | {"modem_in", NULL, "ssp0 Rx"}, |
| 237 | |
| 238 | {"AIF2 Playback", NULL, "ssp0 Tx"}, |
| 239 | {"ssp0 Rx", NULL, "AIF2 Capture"}, |
| 240 | }; |
| 241 | |
Pierre-Louis Bossart | 68817cd | 2016-08-12 16:27:45 -0500 | [diff] [blame] | 242 | static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = { |
| 243 | {"Speaker", NULL, "SPOLP"}, |
| 244 | {"Speaker", NULL, "SPOLN"}, |
| 245 | {"Speaker", NULL, "SPORP"}, |
| 246 | {"Speaker", NULL, "SPORN"}, |
| 247 | }; |
| 248 | |
| 249 | static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = { |
| 250 | {"Speaker", NULL, "SPOLP"}, |
| 251 | {"Speaker", NULL, "SPOLN"}, |
| 252 | }; |
| 253 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 254 | static const struct snd_kcontrol_new byt_rt5640_controls[] = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 255 | SOC_DAPM_PIN_SWITCH("Headphone"), |
| 256 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
Pierre-Louis Bossart | e2be1da | 2015-12-17 20:35:40 -0600 | [diff] [blame] | 257 | SOC_DAPM_PIN_SWITCH("Internal Mic"), |
| 258 | SOC_DAPM_PIN_SWITCH("Speaker"), |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 259 | }; |
| 260 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 261 | static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 262 | struct snd_pcm_hw_params *params) |
| 263 | { |
| 264 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 265 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 266 | int ret; |
| 267 | |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 268 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1, |
| 269 | params_rate(params) * 512, |
| 270 | SND_SOC_CLOCK_IN); |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 271 | |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 272 | if (ret < 0) { |
| 273 | dev_err(rtd->dev, "can't set codec clock %d\n", ret); |
| 274 | return ret; |
| 275 | } |
| 276 | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 277 | if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) { |
| 278 | /* use bitclock as PLL input */ |
| 279 | if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) || |
| 280 | (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) { |
Pierre-Louis Bossart | 038a50e | 2016-08-12 16:27:52 -0500 | [diff] [blame] | 281 | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 282 | /* 2x16 bit slots on SSP0 */ |
| 283 | ret = snd_soc_dai_set_pll(codec_dai, 0, |
| 284 | RT5640_PLL1_S_BCLK1, |
| 285 | params_rate(params) * 32, |
| 286 | params_rate(params) * 512); |
| 287 | } else { |
| 288 | /* 2x15 bit slots on SSP2 */ |
| 289 | ret = snd_soc_dai_set_pll(codec_dai, 0, |
| 290 | RT5640_PLL1_S_BCLK1, |
| 291 | params_rate(params) * 50, |
| 292 | params_rate(params) * 512); |
| 293 | } |
Pierre-Louis Bossart | 038a50e | 2016-08-12 16:27:52 -0500 | [diff] [blame] | 294 | } else { |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 295 | if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) { |
| 296 | ret = snd_soc_dai_set_pll(codec_dai, 0, |
| 297 | RT5640_PLL1_S_MCLK, |
| 298 | 25000000, |
| 299 | params_rate(params) * 512); |
| 300 | } else { |
| 301 | ret = snd_soc_dai_set_pll(codec_dai, 0, |
| 302 | RT5640_PLL1_S_MCLK, |
| 303 | 19200000, |
| 304 | params_rate(params) * 512); |
| 305 | } |
Pierre-Louis Bossart | 038a50e | 2016-08-12 16:27:52 -0500 | [diff] [blame] | 306 | } |
| 307 | |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 308 | if (ret < 0) { |
| 309 | dev_err(rtd->dev, "can't set codec pll: %d\n", ret); |
| 310 | return ret; |
| 311 | } |
| 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 316 | static int byt_rt5640_quirk_cb(const struct dmi_system_id *id) |
| 317 | { |
| 318 | byt_rt5640_quirk = (unsigned long)id->driver_data; |
| 319 | return 1; |
| 320 | } |
| 321 | |
| 322 | static const struct dmi_system_id byt_rt5640_quirk_table[] = { |
| 323 | { |
| 324 | .callback = byt_rt5640_quirk_cb, |
| 325 | .matches = { |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 326 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), |
| 327 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"), |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 328 | }, |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 329 | .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP | |
| 330 | BYT_RT5640_MCLK_EN), |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 331 | }, |
| 332 | { |
| 333 | .callback = byt_rt5640_quirk_cb, |
| 334 | .matches = { |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 335 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), |
| 336 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"), |
| 337 | }, |
Pierre-Louis Bossart | 68817cd | 2016-08-12 16:27:45 -0500 | [diff] [blame] | 338 | .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP | |
Pierre-Louis Bossart | 5d98f58 | 2016-08-12 16:27:46 -0500 | [diff] [blame] | 339 | BYT_RT5640_MONO_SPEAKER | |
Pierre-Louis Bossart | e214f5e | 2016-08-12 16:27:53 -0500 | [diff] [blame] | 340 | BYT_RT5640_DIFF_MIC | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 341 | BYT_RT5640_SSP0_AIF2 | |
| 342 | BYT_RT5640_MCLK_EN |
Pierre-Louis Bossart | 68817cd | 2016-08-12 16:27:45 -0500 | [diff] [blame] | 343 | ), |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 344 | }, |
| 345 | { |
| 346 | .callback = byt_rt5640_quirk_cb, |
| 347 | .matches = { |
| 348 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "DellInc."), |
| 349 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"), |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 350 | }, |
| 351 | .driver_data = (unsigned long *)(BYT_RT5640_DMIC2_MAP | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 352 | BYT_RT5640_DMIC_EN | |
| 353 | BYT_RT5640_MCLK_EN), |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 354 | }, |
Jorge Fernandez Monteagudo | 55fc205 | 2016-01-04 17:20:30 -0600 | [diff] [blame] | 355 | { |
| 356 | .callback = byt_rt5640_quirk_cb, |
| 357 | .matches = { |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 358 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), |
| 359 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"), |
Jorge Fernandez Monteagudo | 55fc205 | 2016-01-04 17:20:30 -0600 | [diff] [blame] | 360 | }, |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 361 | .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP | |
| 362 | BYT_RT5640_MCLK_EN), |
Jorge Fernandez Monteagudo | 55fc205 | 2016-01-04 17:20:30 -0600 | [diff] [blame] | 363 | }, |
Irina Tirdea | 0565e77 | 2016-08-12 16:27:58 -0500 | [diff] [blame] | 364 | { |
| 365 | .callback = byt_rt5640_quirk_cb, |
| 366 | .matches = { |
| 367 | DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"), |
| 368 | DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"), |
| 369 | }, |
| 370 | .driver_data = (unsigned long *)(BYT_RT5640_DMIC1_MAP | |
| 371 | BYT_RT5640_DMIC_EN), |
| 372 | }, |
Pierre-Louis Bossart | ec1c90e | 2016-08-12 16:27:59 -0500 | [diff] [blame] | 373 | { |
| 374 | .callback = byt_rt5640_quirk_cb, |
| 375 | .matches = { |
| 376 | DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"), |
| 377 | DMI_MATCH(DMI_BOARD_NAME, "tPAD"), |
| 378 | }, |
| 379 | .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | |
| 380 | BYT_RT5640_MCLK_EN | |
| 381 | BYT_RT5640_SSP0_AIF1), |
| 382 | }, |
Pierre-Louis Bossart | 8f98307d | 2016-08-16 18:28:22 -0500 | [diff] [blame] | 383 | { |
| 384 | .callback = byt_rt5640_quirk_cb, |
| 385 | .matches = { |
| 386 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 387 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"), |
| 388 | }, |
| 389 | .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP | |
| 390 | BYT_RT5640_MCLK_EN | |
| 391 | BYT_RT5640_SSP0_AIF1), |
| 392 | |
| 393 | }, |
youling257 | 5718004 | 2017-01-04 15:44:53 -0600 | [diff] [blame] | 394 | { |
| 395 | .callback = byt_rt5640_quirk_cb, |
| 396 | .matches = { |
| 397 | DMI_MATCH(DMI_SYS_VENDOR, "Insyde"), |
| 398 | }, |
| 399 | .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | |
| 400 | BYT_RT5640_MCLK_EN | |
| 401 | BYT_RT5640_SSP0_AIF1), |
| 402 | |
| 403 | }, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 404 | {} |
| 405 | }; |
| 406 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 407 | static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime) |
| 408 | { |
| 409 | int ret; |
| 410 | struct snd_soc_codec *codec = runtime->codec; |
| 411 | struct snd_soc_card *card = runtime->card; |
| 412 | const struct snd_soc_dapm_route *custom_map; |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 413 | struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card); |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 414 | int num_routes; |
| 415 | |
| 416 | card->dapm.idle_bias_off = true; |
| 417 | |
Pierre-Louis Bossart | 0ec66e2d | 2016-01-04 17:20:27 -0600 | [diff] [blame] | 418 | rt5640_sel_asrc_clk_src(codec, |
| 419 | RT5640_DA_STEREO_FILTER | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 420 | RT5640_DA_MONO_L_FILTER | |
| 421 | RT5640_DA_MONO_R_FILTER | |
| 422 | RT5640_AD_STEREO_FILTER | |
| 423 | RT5640_AD_MONO_L_FILTER | |
| 424 | RT5640_AD_MONO_R_FILTER, |
Pierre-Louis Bossart | 0ec66e2d | 2016-01-04 17:20:27 -0600 | [diff] [blame] | 425 | RT5640_CLK_SEL_ASRC); |
| 426 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 427 | ret = snd_soc_add_card_controls(card, byt_rt5640_controls, |
| 428 | ARRAY_SIZE(byt_rt5640_controls)); |
| 429 | if (ret) { |
| 430 | dev_err(card->dev, "unable to add card controls\n"); |
| 431 | return ret; |
| 432 | } |
| 433 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 434 | switch (BYT_RT5640_MAP(byt_rt5640_quirk)) { |
| 435 | case BYT_RT5640_IN1_MAP: |
| 436 | custom_map = byt_rt5640_intmic_in1_map; |
| 437 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map); |
| 438 | break; |
Pierre-Louis Bossart | 59e8b65 | 2016-08-12 16:27:54 -0500 | [diff] [blame] | 439 | case BYT_RT5640_IN3_MAP: |
| 440 | custom_map = byt_rt5640_intmic_in3_map; |
| 441 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map); |
| 442 | break; |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 443 | case BYT_RT5640_DMIC2_MAP: |
| 444 | custom_map = byt_rt5640_intmic_dmic2_map; |
| 445 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map); |
| 446 | break; |
| 447 | default: |
| 448 | custom_map = byt_rt5640_intmic_dmic1_map; |
| 449 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map); |
| 450 | } |
| 451 | |
| 452 | ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes); |
| 453 | if (ret) |
| 454 | return ret; |
| 455 | |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame] | 456 | if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) { |
| 457 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 458 | byt_rt5640_ssp2_aif2_map, |
| 459 | ARRAY_SIZE(byt_rt5640_ssp2_aif2_map)); |
Pierre-Louis Bossart | f47088d | 2016-08-12 16:27:51 -0500 | [diff] [blame] | 460 | } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) { |
| 461 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 462 | byt_rt5640_ssp0_aif1_map, |
| 463 | ARRAY_SIZE(byt_rt5640_ssp0_aif1_map)); |
| 464 | } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) { |
| 465 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 466 | byt_rt5640_ssp0_aif2_map, |
| 467 | ARRAY_SIZE(byt_rt5640_ssp0_aif2_map)); |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame] | 468 | } else { |
| 469 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 470 | byt_rt5640_ssp2_aif1_map, |
| 471 | ARRAY_SIZE(byt_rt5640_ssp2_aif1_map)); |
| 472 | } |
| 473 | if (ret) |
| 474 | return ret; |
| 475 | |
Pierre-Louis Bossart | 68817cd | 2016-08-12 16:27:45 -0500 | [diff] [blame] | 476 | if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) { |
| 477 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 478 | byt_rt5640_mono_spk_map, |
| 479 | ARRAY_SIZE(byt_rt5640_mono_spk_map)); |
| 480 | } else { |
| 481 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 482 | byt_rt5640_stereo_spk_map, |
| 483 | ARRAY_SIZE(byt_rt5640_stereo_spk_map)); |
| 484 | } |
| 485 | if (ret) |
| 486 | return ret; |
| 487 | |
Pierre-Louis Bossart | 5d98f58 | 2016-08-12 16:27:46 -0500 | [diff] [blame] | 488 | if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC) { |
| 489 | snd_soc_update_bits(codec, RT5640_IN1_IN2, RT5640_IN_DF1, |
| 490 | RT5640_IN_DF1); |
| 491 | } |
| 492 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 493 | if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN) { |
| 494 | ret = rt5640_dmic_enable(codec, 0, 0); |
| 495 | if (ret) |
| 496 | return ret; |
| 497 | } |
| 498 | |
| 499 | snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone"); |
| 500 | snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker"); |
| 501 | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 502 | if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && priv->mclk) { |
| 503 | /* |
| 504 | * The firmware might enable the clock at |
| 505 | * boot (this information may or may not |
| 506 | * be reflected in the enable clock register). |
| 507 | * To change the rate we must disable the clock |
| 508 | * first to cover these cases. Due to common |
| 509 | * clock framework restrictions that do not allow |
| 510 | * to disable a clock that has not been enabled, |
| 511 | * we need to enable the clock first. |
| 512 | */ |
| 513 | ret = clk_prepare_enable(priv->mclk); |
| 514 | if (!ret) |
| 515 | clk_disable_unprepare(priv->mclk); |
| 516 | |
| 517 | if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) |
| 518 | ret = clk_set_rate(priv->mclk, 25000000); |
| 519 | else |
| 520 | ret = clk_set_rate(priv->mclk, 19200000); |
| 521 | |
| 522 | if (ret) |
| 523 | dev_err(card->dev, "unable to set MCLK rate\n"); |
| 524 | } |
| 525 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 526 | return ret; |
| 527 | } |
| 528 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 529 | static const struct snd_soc_pcm_stream byt_rt5640_dai_params = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 530 | .formats = SNDRV_PCM_FMTBIT_S24_LE, |
| 531 | .rate_min = 48000, |
| 532 | .rate_max = 48000, |
| 533 | .channels_min = 2, |
| 534 | .channels_max = 2, |
| 535 | }; |
| 536 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 537 | static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 538 | struct snd_pcm_hw_params *params) |
| 539 | { |
| 540 | struct snd_interval *rate = hw_param_interval(params, |
| 541 | SNDRV_PCM_HW_PARAM_RATE); |
| 542 | struct snd_interval *channels = hw_param_interval(params, |
| 543 | SNDRV_PCM_HW_PARAM_CHANNELS); |
Sebastien Guiriec | 3f27ded | 2015-12-17 20:35:39 -0600 | [diff] [blame] | 544 | int ret; |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 545 | |
Pierre-Louis Bossart | 038a50e | 2016-08-12 16:27:52 -0500 | [diff] [blame] | 546 | /* The DSP will covert the FE rate to 48k, stereo */ |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 547 | rate->min = rate->max = 48000; |
| 548 | channels->min = channels->max = 2; |
| 549 | |
Pierre-Louis Bossart | 038a50e | 2016-08-12 16:27:52 -0500 | [diff] [blame] | 550 | if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) || |
| 551 | (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) { |
Sebastien Guiriec | 3f27ded | 2015-12-17 20:35:39 -0600 | [diff] [blame] | 552 | |
Pierre-Louis Bossart | 8f98307d | 2016-08-16 18:28:22 -0500 | [diff] [blame] | 553 | /* set SSP0 to 16-bit */ |
Pierre-Louis Bossart | 038a50e | 2016-08-12 16:27:52 -0500 | [diff] [blame] | 554 | params_set_format(params, SNDRV_PCM_FORMAT_S16_LE); |
| 555 | |
| 556 | /* |
| 557 | * Default mode for SSP configuration is TDM 4 slot, override config |
| 558 | * with explicit setting to I2S 2ch 16-bit. The word length is set with |
| 559 | * dai_set_tdm_slot() since there is no other API exposed |
| 560 | */ |
| 561 | ret = snd_soc_dai_set_fmt(rtd->cpu_dai, |
| 562 | SND_SOC_DAIFMT_I2S | |
Pierre-Louis Bossart | f12f5c8 | 2017-01-26 14:09:29 -0600 | [diff] [blame] | 563 | SND_SOC_DAIFMT_NB_NF | |
Pierre-Louis Bossart | 038a50e | 2016-08-12 16:27:52 -0500 | [diff] [blame] | 564 | SND_SOC_DAIFMT_CBS_CFS |
| 565 | ); |
| 566 | if (ret < 0) { |
| 567 | dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret); |
| 568 | return ret; |
| 569 | } |
| 570 | |
| 571 | ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 16); |
| 572 | if (ret < 0) { |
| 573 | dev_err(rtd->dev, "can't set I2S config, err %d\n", ret); |
| 574 | return ret; |
| 575 | } |
| 576 | |
| 577 | } else { |
| 578 | |
| 579 | /* set SSP2 to 24-bit */ |
| 580 | params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); |
| 581 | |
| 582 | /* |
| 583 | * Default mode for SSP configuration is TDM 4 slot, override config |
| 584 | * with explicit setting to I2S 2ch 24-bit. The word length is set with |
| 585 | * dai_set_tdm_slot() since there is no other API exposed |
| 586 | */ |
| 587 | ret = snd_soc_dai_set_fmt(rtd->cpu_dai, |
| 588 | SND_SOC_DAIFMT_I2S | |
Pierre-Louis Bossart | f12f5c8 | 2017-01-26 14:09:29 -0600 | [diff] [blame] | 589 | SND_SOC_DAIFMT_NB_NF | |
Pierre-Louis Bossart | 038a50e | 2016-08-12 16:27:52 -0500 | [diff] [blame] | 590 | SND_SOC_DAIFMT_CBS_CFS |
| 591 | ); |
| 592 | if (ret < 0) { |
| 593 | dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret); |
| 594 | return ret; |
| 595 | } |
| 596 | |
| 597 | ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24); |
| 598 | if (ret < 0) { |
| 599 | dev_err(rtd->dev, "can't set I2S config, err %d\n", ret); |
| 600 | return ret; |
| 601 | } |
Sebastien Guiriec | 3f27ded | 2015-12-17 20:35:39 -0600 | [diff] [blame] | 602 | } |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 603 | return 0; |
| 604 | } |
| 605 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 606 | static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream) |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 607 | { |
Lars-Peter Clausen | d0a1b66 | 2015-10-18 15:39:30 +0200 | [diff] [blame] | 608 | return snd_pcm_hw_constraint_single(substream->runtime, |
| 609 | SNDRV_PCM_HW_PARAM_RATE, 48000); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 610 | } |
| 611 | |
Julia Lawall | 9b6fdef | 2016-10-15 16:55:49 +0200 | [diff] [blame] | 612 | static const struct snd_soc_ops byt_rt5640_aif1_ops = { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 613 | .startup = byt_rt5640_aif1_startup, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 614 | }; |
| 615 | |
Julia Lawall | 9b6fdef | 2016-10-15 16:55:49 +0200 | [diff] [blame] | 616 | static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 617 | .hw_params = byt_rt5640_aif1_hw_params, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 618 | }; |
| 619 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 620 | static struct snd_soc_dai_link byt_rt5640_dais[] = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 621 | [MERR_DPCM_AUDIO] = { |
| 622 | .name = "Baytrail Audio Port", |
| 623 | .stream_name = "Baytrail Audio", |
| 624 | .cpu_dai_name = "media-cpu-dai", |
| 625 | .codec_dai_name = "snd-soc-dummy-dai", |
| 626 | .codec_name = "snd-soc-dummy", |
| 627 | .platform_name = "sst-mfld-platform", |
| 628 | .ignore_suspend = 1, |
| 629 | .dynamic = 1, |
| 630 | .dpcm_playback = 1, |
| 631 | .dpcm_capture = 1, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 632 | .ops = &byt_rt5640_aif1_ops, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 633 | }, |
Pierre-Louis Bossart | d35eb96 | 2015-12-17 20:35:45 -0600 | [diff] [blame] | 634 | [MERR_DPCM_DEEP_BUFFER] = { |
| 635 | .name = "Deep-Buffer Audio Port", |
| 636 | .stream_name = "Deep-Buffer Audio", |
| 637 | .cpu_dai_name = "deepbuffer-cpu-dai", |
| 638 | .codec_dai_name = "snd-soc-dummy-dai", |
| 639 | .codec_name = "snd-soc-dummy", |
| 640 | .platform_name = "sst-mfld-platform", |
| 641 | .ignore_suspend = 1, |
| 642 | .nonatomic = true, |
| 643 | .dynamic = 1, |
| 644 | .dpcm_playback = 1, |
| 645 | .ops = &byt_rt5640_aif1_ops, |
| 646 | }, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 647 | [MERR_DPCM_COMPR] = { |
| 648 | .name = "Baytrail Compressed Port", |
| 649 | .stream_name = "Baytrail Compress", |
| 650 | .cpu_dai_name = "compress-cpu-dai", |
| 651 | .codec_dai_name = "snd-soc-dummy-dai", |
| 652 | .codec_name = "snd-soc-dummy", |
| 653 | .platform_name = "sst-mfld-platform", |
| 654 | }, |
| 655 | /* back ends */ |
| 656 | { |
| 657 | .name = "SSP2-Codec", |
Mengdong Lin | 2f0ad49 | 2016-04-19 13:12:35 +0800 | [diff] [blame] | 658 | .id = 1, |
Pierre-Louis Bossart | f47088d | 2016-08-12 16:27:51 -0500 | [diff] [blame] | 659 | .cpu_dai_name = "ssp2-port", /* overwritten for ssp0 routing */ |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 660 | .platform_name = "sst-mfld-platform", |
| 661 | .no_pcm = 1, |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame] | 662 | .codec_dai_name = "rt5640-aif1", /* changed w/ quirk */ |
Pierre-Louis Bossart | 7762ef4 | 2016-01-04 17:20:29 -0600 | [diff] [blame] | 663 | .codec_name = "i2c-10EC5640:00", /* overwritten with HID */ |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 664 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 665 | | SND_SOC_DAIFMT_CBS_CFS, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 666 | .be_hw_params_fixup = byt_rt5640_codec_fixup, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 667 | .ignore_suspend = 1, |
| 668 | .dpcm_playback = 1, |
| 669 | .dpcm_capture = 1, |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 670 | .init = byt_rt5640_init, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 671 | .ops = &byt_rt5640_be_ssp2_ops, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 672 | }, |
| 673 | }; |
| 674 | |
| 675 | /* SoC card */ |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 676 | static struct snd_soc_card byt_rt5640_card = { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 677 | .name = "bytcr-rt5640", |
Axel Lin | 54d8697 | 2015-08-21 20:59:21 +0800 | [diff] [blame] | 678 | .owner = THIS_MODULE, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 679 | .dai_link = byt_rt5640_dais, |
| 680 | .num_links = ARRAY_SIZE(byt_rt5640_dais), |
| 681 | .dapm_widgets = byt_rt5640_widgets, |
| 682 | .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets), |
| 683 | .dapm_routes = byt_rt5640_audio_map, |
| 684 | .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map), |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 685 | .fully_routed = true, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 686 | }; |
| 687 | |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 688 | static char byt_rt5640_codec_name[16]; /* i2c-<HID>:00 with HID being 8 chars */ |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame] | 689 | static char byt_rt5640_codec_aif_name[12]; /* = "rt5640-aif[1|2]" */ |
Pierre-Louis Bossart | f47088d | 2016-08-12 16:27:51 -0500 | [diff] [blame] | 690 | static char byt_rt5640_cpu_dai_name[10]; /* = "ssp[0|2]-port" */ |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 691 | |
Pierre-Louis Bossart | e214f5e | 2016-08-12 16:27:53 -0500 | [diff] [blame] | 692 | static bool is_valleyview(void) |
| 693 | { |
Pierre-Louis Bossart | cac1773 | 2016-08-16 18:28:21 -0500 | [diff] [blame] | 694 | static const struct x86_cpu_id cpu_ids[] = { |
Pierre-Louis Bossart | e214f5e | 2016-08-12 16:27:53 -0500 | [diff] [blame] | 695 | { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */ |
| 696 | {} |
| 697 | }; |
| 698 | |
| 699 | if (!x86_match_cpu(cpu_ids)) |
| 700 | return false; |
| 701 | return true; |
| 702 | } |
| 703 | |
Pierre-Louis Bossart | 64e8430 | 2016-11-12 18:07:45 -0600 | [diff] [blame] | 704 | struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */ |
| 705 | u64 aif_value; /* 1: AIF1, 2: AIF2 */ |
| 706 | u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */ |
| 707 | }; |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 708 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 709 | static int snd_byt_rt5640_mc_probe(struct platform_device *pdev) |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 710 | { |
| 711 | int ret_val = 0; |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 712 | struct sst_acpi_mach *mach; |
Pierre-Louis Bossart | a232b96 | 2016-03-03 21:36:38 -0600 | [diff] [blame] | 713 | const char *i2c_name = NULL; |
| 714 | int i; |
| 715 | int dai_index; |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 716 | struct byt_rt5640_private *priv; |
Pierre-Louis Bossart | 64e8430 | 2016-11-12 18:07:45 -0600 | [diff] [blame] | 717 | bool is_bytcr = false; |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 718 | |
| 719 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_ATOMIC); |
| 720 | if (!priv) |
| 721 | return -ENOMEM; |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 722 | |
| 723 | /* register the soc card */ |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 724 | byt_rt5640_card.dev = &pdev->dev; |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 725 | mach = byt_rt5640_card.dev->platform_data; |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 726 | snd_soc_card_set_drvdata(&byt_rt5640_card, priv); |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 727 | |
Pierre-Louis Bossart | a232b96 | 2016-03-03 21:36:38 -0600 | [diff] [blame] | 728 | /* fix index of codec dai */ |
| 729 | dai_index = MERR_DPCM_COMPR + 1; |
| 730 | for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) { |
| 731 | if (!strcmp(byt_rt5640_dais[i].codec_name, "i2c-10EC5640:00")) { |
| 732 | dai_index = i; |
| 733 | break; |
| 734 | } |
| 735 | } |
| 736 | |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 737 | /* fixup codec name based on HID */ |
Pierre-Louis Bossart | a232b96 | 2016-03-03 21:36:38 -0600 | [diff] [blame] | 738 | i2c_name = sst_acpi_find_name_from_hid(mach->id); |
| 739 | if (i2c_name != NULL) { |
| 740 | snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name), |
| 741 | "%s%s", "i2c-", i2c_name); |
| 742 | |
| 743 | byt_rt5640_dais[dai_index].codec_name = byt_rt5640_codec_name; |
| 744 | } |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 745 | |
Pierre-Louis Bossart | e214f5e | 2016-08-12 16:27:53 -0500 | [diff] [blame] | 746 | /* |
| 747 | * swap SSP0 if bytcr is detected |
| 748 | * (will be overridden if DMI quirk is detected) |
| 749 | */ |
| 750 | if (is_valleyview()) { |
| 751 | struct sst_platform_info *p_info = mach->pdata; |
| 752 | const struct sst_res_info *res_info = p_info->res_info; |
| 753 | |
Pierre-Louis Bossart | 64e8430 | 2016-11-12 18:07:45 -0600 | [diff] [blame] | 754 | if (res_info->acpi_ipc_irq_index == 0) |
| 755 | is_bytcr = true; |
| 756 | } |
| 757 | |
| 758 | if (is_bytcr) { |
| 759 | /* |
| 760 | * Baytrail CR platforms may have CHAN package in BIOS, try |
| 761 | * to find relevant routing quirk based as done on Windows |
| 762 | * platforms. We have to read the information directly from the |
| 763 | * BIOS, at this stage the card is not created and the links |
| 764 | * with the codec driver/pdata are non-existent |
| 765 | */ |
| 766 | |
| 767 | struct acpi_chan_package chan_package; |
| 768 | |
| 769 | /* format specified: 2 64-bit integers */ |
| 770 | struct acpi_buffer format = {sizeof("NN"), "NN"}; |
| 771 | struct acpi_buffer state = {0, NULL}; |
| 772 | struct sst_acpi_package_context pkg_ctx; |
| 773 | bool pkg_found = false; |
| 774 | |
| 775 | state.length = sizeof(chan_package); |
| 776 | state.pointer = &chan_package; |
| 777 | |
| 778 | pkg_ctx.name = "CHAN"; |
| 779 | pkg_ctx.length = 2; |
| 780 | pkg_ctx.format = &format; |
| 781 | pkg_ctx.state = &state; |
| 782 | pkg_ctx.data_valid = false; |
| 783 | |
| 784 | pkg_found = sst_acpi_find_package_from_hid(mach->id, &pkg_ctx); |
| 785 | if (pkg_found) { |
| 786 | if (chan_package.aif_value == 1) { |
| 787 | dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n"); |
| 788 | byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1; |
| 789 | } else if (chan_package.aif_value == 2) { |
| 790 | dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n"); |
| 791 | byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2; |
| 792 | } else { |
| 793 | dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n"); |
| 794 | pkg_found = false; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | if (!pkg_found) { |
| 799 | /* no BIOS indications, assume SSP0-AIF2 connection */ |
Pierre-Louis Bossart | e214f5e | 2016-08-12 16:27:53 -0500 | [diff] [blame] | 800 | byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2; |
| 801 | } |
Pierre-Louis Bossart | bf46241 | 2016-11-12 18:07:46 -0600 | [diff] [blame] | 802 | |
| 803 | /* change defaults for Baytrail-CR capture */ |
| 804 | byt_rt5640_quirk |= BYT_RT5640_IN1_MAP; |
| 805 | byt_rt5640_quirk |= BYT_RT5640_DIFF_MIC; |
| 806 | } else { |
| 807 | byt_rt5640_quirk |= (BYT_RT5640_DMIC1_MAP | |
| 808 | BYT_RT5640_DMIC_EN); |
Pierre-Louis Bossart | e214f5e | 2016-08-12 16:27:53 -0500 | [diff] [blame] | 809 | } |
| 810 | |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 811 | /* check quirks before creating card */ |
| 812 | dmi_check_system(byt_rt5640_quirk_table); |
Takashi Iwai | 9f2cf73 | 2017-04-23 09:22:56 +0200 | [diff] [blame^] | 813 | if (quirk_override) { |
| 814 | dev_info(&pdev->dev, "Overriding quirk %0x => 0x%x\n", |
| 815 | (unsigned int)byt_rt5640_quirk, quirk_override); |
| 816 | byt_rt5640_quirk = quirk_override; |
| 817 | } |
Pierre-Louis Bossart | d7e60d5 | 2016-08-12 16:28:00 -0500 | [diff] [blame] | 818 | log_quirks(&pdev->dev); |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 819 | |
Pierre-Louis Bossart | f47088d | 2016-08-12 16:27:51 -0500 | [diff] [blame] | 820 | if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) || |
| 821 | (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) { |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame] | 822 | |
| 823 | /* fixup codec aif name */ |
| 824 | snprintf(byt_rt5640_codec_aif_name, |
| 825 | sizeof(byt_rt5640_codec_aif_name), |
| 826 | "%s", "rt5640-aif2"); |
| 827 | |
| 828 | byt_rt5640_dais[dai_index].codec_dai_name = |
| 829 | byt_rt5640_codec_aif_name; |
| 830 | } |
| 831 | |
Pierre-Louis Bossart | f47088d | 2016-08-12 16:27:51 -0500 | [diff] [blame] | 832 | if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) || |
| 833 | (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) { |
| 834 | |
| 835 | /* fixup cpu dai name name */ |
| 836 | snprintf(byt_rt5640_cpu_dai_name, |
| 837 | sizeof(byt_rt5640_cpu_dai_name), |
| 838 | "%s", "ssp0-port"); |
| 839 | |
| 840 | byt_rt5640_dais[dai_index].cpu_dai_name = |
| 841 | byt_rt5640_cpu_dai_name; |
| 842 | } |
| 843 | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 844 | if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && (is_valleyview())) { |
| 845 | priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3"); |
| 846 | if (IS_ERR(priv->mclk)) { |
Pierre-Louis Bossart | 4a8b3a6 | 2016-12-16 10:55:49 -0600 | [diff] [blame] | 847 | ret_val = PTR_ERR(priv->mclk); |
| 848 | |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 849 | dev_err(&pdev->dev, |
Pierre-Louis Bossart | 4a8b3a6 | 2016-12-16 10:55:49 -0600 | [diff] [blame] | 850 | "Failed to get MCLK from pmc_plt_clk_3: %d\n", |
| 851 | ret_val); |
| 852 | |
| 853 | /* |
| 854 | * Fall back to bit clock usage for -ENOENT (clock not |
| 855 | * available likely due to missing dependencies), bail |
| 856 | * for all other errors, including -EPROBE_DEFER |
| 857 | */ |
| 858 | if (ret_val != -ENOENT) |
| 859 | return ret_val; |
| 860 | byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN; |
Irina Tirdea | df1a277 | 2016-08-12 16:27:57 -0500 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 864 | ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card); |
| 865 | |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 866 | if (ret_val) { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 867 | dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n", |
| 868 | ret_val); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 869 | return ret_val; |
| 870 | } |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 871 | platform_set_drvdata(pdev, &byt_rt5640_card); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 872 | return ret_val; |
| 873 | } |
| 874 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 875 | static struct platform_driver snd_byt_rt5640_mc_driver = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 876 | .driver = { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 877 | .name = "bytcr_rt5640", |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 878 | }, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 879 | .probe = snd_byt_rt5640_mc_probe, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 880 | }; |
| 881 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 882 | module_platform_driver(snd_byt_rt5640_mc_driver); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 883 | |
| 884 | MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver"); |
| 885 | MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>"); |
| 886 | MODULE_LICENSE("GPL v2"); |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 887 | MODULE_ALIAS("platform:bytcr_rt5640"); |