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