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