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> |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 27 | #include <sound/pcm.h> |
| 28 | #include <sound/pcm_params.h> |
| 29 | #include <sound/soc.h> |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 30 | #include <sound/jack.h> |
Jie Yang | e56c72d | 2015-04-02 15:37:02 +0800 | [diff] [blame] | 31 | #include "../../codecs/rt5640.h" |
Jie Yang | b97169d | 2015-04-02 15:37:04 +0800 | [diff] [blame] | 32 | #include "../atom/sst-atom-controls.h" |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 33 | #include "../common/sst-acpi.h" |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 34 | |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 35 | enum { |
| 36 | BYT_RT5640_DMIC1_MAP, |
| 37 | BYT_RT5640_DMIC2_MAP, |
| 38 | BYT_RT5640_IN1_MAP, |
| 39 | }; |
| 40 | |
| 41 | #define BYT_RT5640_MAP(quirk) ((quirk) & 0xff) |
| 42 | #define BYT_RT5640_DMIC_EN BIT(16) |
Pierre-Louis Bossart | 68817cd | 2016-08-12 16:27:45 -0500 | [diff] [blame] | 43 | #define BYT_RT5640_MONO_SPEAKER BIT(17) |
Pierre-Louis Bossart | 5d98f58 | 2016-08-12 16:27:46 -0500 | [diff] [blame] | 44 | #define BYT_RT5640_DIFF_MIC BIT(18) /* defaut is single-ended */ |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame^] | 45 | #define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */ |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 46 | |
| 47 | static unsigned long byt_rt5640_quirk = BYT_RT5640_DMIC1_MAP | |
| 48 | BYT_RT5640_DMIC_EN; |
| 49 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 50 | static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 51 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 52 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
Pierre-Louis Bossart | e2be1da | 2015-12-17 20:35:40 -0600 | [diff] [blame] | 53 | SND_SOC_DAPM_MIC("Internal Mic", NULL), |
| 54 | SND_SOC_DAPM_SPK("Speaker", NULL), |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 55 | }; |
| 56 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 57 | static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 58 | {"Headset Mic", NULL, "MICBIAS1"}, |
Pierre-Louis Bossart | e2be1da | 2015-12-17 20:35:40 -0600 | [diff] [blame] | 59 | {"IN2P", NULL, "Headset Mic"}, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 60 | {"Headphone", NULL, "HPOL"}, |
| 61 | {"Headphone", NULL, "HPOR"}, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 62 | }; |
| 63 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 64 | static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = { |
| 65 | {"DMIC1", NULL, "Internal Mic"}, |
| 66 | }; |
| 67 | |
| 68 | static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = { |
| 69 | {"DMIC2", NULL, "Internal Mic"}, |
| 70 | }; |
| 71 | |
| 72 | static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = { |
| 73 | {"Internal Mic", NULL, "MICBIAS1"}, |
| 74 | {"IN1P", NULL, "Internal Mic"}, |
| 75 | }; |
| 76 | |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame^] | 77 | static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = { |
| 78 | {"ssp2 Tx", NULL, "codec_out0"}, |
| 79 | {"ssp2 Tx", NULL, "codec_out1"}, |
| 80 | {"codec_in0", NULL, "ssp2 Rx"}, |
| 81 | {"codec_in1", NULL, "ssp2 Rx"}, |
| 82 | |
| 83 | {"AIF1 Playback", NULL, "ssp2 Tx"}, |
| 84 | {"ssp2 Rx", NULL, "AIF1 Capture"}, |
| 85 | }; |
| 86 | |
| 87 | static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = { |
| 88 | {"ssp2 Tx", NULL, "codec_out0"}, |
| 89 | {"ssp2 Tx", NULL, "codec_out1"}, |
| 90 | {"codec_in0", NULL, "ssp2 Rx"}, |
| 91 | {"codec_in1", NULL, "ssp2 Rx"}, |
| 92 | |
| 93 | {"AIF2 Playback", NULL, "ssp2 Tx"}, |
| 94 | {"ssp2 Rx", NULL, "AIF2 Capture"}, |
| 95 | }; |
| 96 | |
Pierre-Louis Bossart | 68817cd | 2016-08-12 16:27:45 -0500 | [diff] [blame] | 97 | static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = { |
| 98 | {"Speaker", NULL, "SPOLP"}, |
| 99 | {"Speaker", NULL, "SPOLN"}, |
| 100 | {"Speaker", NULL, "SPORP"}, |
| 101 | {"Speaker", NULL, "SPORN"}, |
| 102 | }; |
| 103 | |
| 104 | static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = { |
| 105 | {"Speaker", NULL, "SPOLP"}, |
| 106 | {"Speaker", NULL, "SPOLN"}, |
| 107 | }; |
| 108 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 109 | static const struct snd_kcontrol_new byt_rt5640_controls[] = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 110 | SOC_DAPM_PIN_SWITCH("Headphone"), |
| 111 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
Pierre-Louis Bossart | e2be1da | 2015-12-17 20:35:40 -0600 | [diff] [blame] | 112 | SOC_DAPM_PIN_SWITCH("Internal Mic"), |
| 113 | SOC_DAPM_PIN_SWITCH("Speaker"), |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 114 | }; |
| 115 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 116 | 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] | 117 | struct snd_pcm_hw_params *params) |
| 118 | { |
| 119 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 120 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 121 | int ret; |
| 122 | |
| 123 | snd_soc_dai_set_bclk_ratio(codec_dai, 50); |
| 124 | |
| 125 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1, |
| 126 | params_rate(params) * 512, |
| 127 | SND_SOC_CLOCK_IN); |
| 128 | if (ret < 0) { |
| 129 | dev_err(rtd->dev, "can't set codec clock %d\n", ret); |
| 130 | return ret; |
| 131 | } |
| 132 | |
| 133 | ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1, |
| 134 | params_rate(params) * 50, |
| 135 | params_rate(params) * 512); |
| 136 | if (ret < 0) { |
| 137 | dev_err(rtd->dev, "can't set codec pll: %d\n", ret); |
| 138 | return ret; |
| 139 | } |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 144 | static int byt_rt5640_quirk_cb(const struct dmi_system_id *id) |
| 145 | { |
| 146 | byt_rt5640_quirk = (unsigned long)id->driver_data; |
| 147 | return 1; |
| 148 | } |
| 149 | |
| 150 | static const struct dmi_system_id byt_rt5640_quirk_table[] = { |
| 151 | { |
| 152 | .callback = byt_rt5640_quirk_cb, |
| 153 | .matches = { |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 154 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), |
| 155 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"), |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 156 | }, |
| 157 | .driver_data = (unsigned long *)BYT_RT5640_IN1_MAP, |
| 158 | }, |
| 159 | { |
| 160 | .callback = byt_rt5640_quirk_cb, |
| 161 | .matches = { |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 162 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), |
| 163 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"), |
| 164 | }, |
Pierre-Louis Bossart | 68817cd | 2016-08-12 16:27:45 -0500 | [diff] [blame] | 165 | .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP | |
Pierre-Louis Bossart | 5d98f58 | 2016-08-12 16:27:46 -0500 | [diff] [blame] | 166 | BYT_RT5640_MONO_SPEAKER | |
| 167 | BYT_RT5640_DIFF_MIC |
Pierre-Louis Bossart | 68817cd | 2016-08-12 16:27:45 -0500 | [diff] [blame] | 168 | ), |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 169 | }, |
| 170 | { |
| 171 | .callback = byt_rt5640_quirk_cb, |
| 172 | .matches = { |
| 173 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "DellInc."), |
| 174 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"), |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 175 | }, |
| 176 | .driver_data = (unsigned long *)(BYT_RT5640_DMIC2_MAP | |
| 177 | BYT_RT5640_DMIC_EN), |
| 178 | }, |
Jorge Fernandez Monteagudo | 55fc205 | 2016-01-04 17:20:30 -0600 | [diff] [blame] | 179 | { |
| 180 | .callback = byt_rt5640_quirk_cb, |
| 181 | .matches = { |
Pierre-Louis Bossart | 73442e3 | 2016-08-12 16:27:44 -0500 | [diff] [blame] | 182 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), |
| 183 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"), |
Jorge Fernandez Monteagudo | 55fc205 | 2016-01-04 17:20:30 -0600 | [diff] [blame] | 184 | }, |
| 185 | .driver_data = (unsigned long *)BYT_RT5640_IN1_MAP, |
| 186 | }, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 187 | {} |
| 188 | }; |
| 189 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 190 | static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime) |
| 191 | { |
| 192 | int ret; |
| 193 | struct snd_soc_codec *codec = runtime->codec; |
| 194 | struct snd_soc_card *card = runtime->card; |
| 195 | const struct snd_soc_dapm_route *custom_map; |
| 196 | int num_routes; |
| 197 | |
| 198 | card->dapm.idle_bias_off = true; |
| 199 | |
Pierre-Louis Bossart | 0ec66e2d | 2016-01-04 17:20:27 -0600 | [diff] [blame] | 200 | rt5640_sel_asrc_clk_src(codec, |
| 201 | RT5640_DA_STEREO_FILTER | |
| 202 | RT5640_AD_STEREO_FILTER, |
| 203 | RT5640_CLK_SEL_ASRC); |
| 204 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 205 | ret = snd_soc_add_card_controls(card, byt_rt5640_controls, |
| 206 | ARRAY_SIZE(byt_rt5640_controls)); |
| 207 | if (ret) { |
| 208 | dev_err(card->dev, "unable to add card controls\n"); |
| 209 | return ret; |
| 210 | } |
| 211 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 212 | switch (BYT_RT5640_MAP(byt_rt5640_quirk)) { |
| 213 | case BYT_RT5640_IN1_MAP: |
| 214 | custom_map = byt_rt5640_intmic_in1_map; |
| 215 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map); |
| 216 | break; |
| 217 | case BYT_RT5640_DMIC2_MAP: |
| 218 | custom_map = byt_rt5640_intmic_dmic2_map; |
| 219 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map); |
| 220 | break; |
| 221 | default: |
| 222 | custom_map = byt_rt5640_intmic_dmic1_map; |
| 223 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map); |
| 224 | } |
| 225 | |
| 226 | ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes); |
| 227 | if (ret) |
| 228 | return ret; |
| 229 | |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame^] | 230 | if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) { |
| 231 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 232 | byt_rt5640_ssp2_aif2_map, |
| 233 | ARRAY_SIZE(byt_rt5640_ssp2_aif2_map)); |
| 234 | } else { |
| 235 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 236 | byt_rt5640_ssp2_aif1_map, |
| 237 | ARRAY_SIZE(byt_rt5640_ssp2_aif1_map)); |
| 238 | } |
| 239 | if (ret) |
| 240 | return ret; |
| 241 | |
Pierre-Louis Bossart | 68817cd | 2016-08-12 16:27:45 -0500 | [diff] [blame] | 242 | if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) { |
| 243 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 244 | byt_rt5640_mono_spk_map, |
| 245 | ARRAY_SIZE(byt_rt5640_mono_spk_map)); |
| 246 | } else { |
| 247 | ret = snd_soc_dapm_add_routes(&card->dapm, |
| 248 | byt_rt5640_stereo_spk_map, |
| 249 | ARRAY_SIZE(byt_rt5640_stereo_spk_map)); |
| 250 | } |
| 251 | if (ret) |
| 252 | return ret; |
| 253 | |
Pierre-Louis Bossart | 5d98f58 | 2016-08-12 16:27:46 -0500 | [diff] [blame] | 254 | if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC) { |
| 255 | snd_soc_update_bits(codec, RT5640_IN1_IN2, RT5640_IN_DF1, |
| 256 | RT5640_IN_DF1); |
| 257 | } |
| 258 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 259 | if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN) { |
| 260 | ret = rt5640_dmic_enable(codec, 0, 0); |
| 261 | if (ret) |
| 262 | return ret; |
| 263 | } |
| 264 | |
| 265 | snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone"); |
| 266 | snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker"); |
| 267 | |
| 268 | return ret; |
| 269 | } |
| 270 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 271 | static const struct snd_soc_pcm_stream byt_rt5640_dai_params = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 272 | .formats = SNDRV_PCM_FMTBIT_S24_LE, |
| 273 | .rate_min = 48000, |
| 274 | .rate_max = 48000, |
| 275 | .channels_min = 2, |
| 276 | .channels_max = 2, |
| 277 | }; |
| 278 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 279 | 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] | 280 | struct snd_pcm_hw_params *params) |
| 281 | { |
| 282 | struct snd_interval *rate = hw_param_interval(params, |
| 283 | SNDRV_PCM_HW_PARAM_RATE); |
| 284 | struct snd_interval *channels = hw_param_interval(params, |
| 285 | SNDRV_PCM_HW_PARAM_CHANNELS); |
Sebastien Guiriec | 3f27ded | 2015-12-17 20:35:39 -0600 | [diff] [blame] | 286 | int ret; |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 287 | |
| 288 | /* The DSP will covert the FE rate to 48k, stereo, 24bits */ |
| 289 | rate->min = rate->max = 48000; |
| 290 | channels->min = channels->max = 2; |
| 291 | |
| 292 | /* set SSP2 to 24-bit */ |
Fang, Yang A | 369a9f5 | 2015-02-09 00:18:12 -0800 | [diff] [blame] | 293 | params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); |
Sebastien Guiriec | 3f27ded | 2015-12-17 20:35:39 -0600 | [diff] [blame] | 294 | |
| 295 | /* |
| 296 | * Default mode for SSP configuration is TDM 4 slot, override config |
| 297 | * with explicit setting to I2S 2ch 24-bit. The word length is set with |
| 298 | * dai_set_tdm_slot() since there is no other API exposed |
| 299 | */ |
| 300 | ret = snd_soc_dai_set_fmt(rtd->cpu_dai, |
| 301 | SND_SOC_DAIFMT_I2S | |
| 302 | SND_SOC_DAIFMT_NB_IF | |
| 303 | SND_SOC_DAIFMT_CBS_CFS |
| 304 | ); |
| 305 | if (ret < 0) { |
| 306 | dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret); |
| 307 | return ret; |
| 308 | } |
| 309 | |
| 310 | ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24); |
| 311 | if (ret < 0) { |
| 312 | dev_err(rtd->dev, "can't set I2S config, err %d\n", ret); |
| 313 | return ret; |
| 314 | } |
| 315 | |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 316 | return 0; |
| 317 | } |
| 318 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 319 | static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream) |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 320 | { |
Lars-Peter Clausen | d0a1b66 | 2015-10-18 15:39:30 +0200 | [diff] [blame] | 321 | return snd_pcm_hw_constraint_single(substream->runtime, |
| 322 | SNDRV_PCM_HW_PARAM_RATE, 48000); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 323 | } |
| 324 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 325 | static struct snd_soc_ops byt_rt5640_aif1_ops = { |
| 326 | .startup = byt_rt5640_aif1_startup, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 327 | }; |
| 328 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 329 | static struct snd_soc_ops byt_rt5640_be_ssp2_ops = { |
| 330 | .hw_params = byt_rt5640_aif1_hw_params, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 331 | }; |
| 332 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 333 | static struct snd_soc_dai_link byt_rt5640_dais[] = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 334 | [MERR_DPCM_AUDIO] = { |
| 335 | .name = "Baytrail Audio Port", |
| 336 | .stream_name = "Baytrail Audio", |
| 337 | .cpu_dai_name = "media-cpu-dai", |
| 338 | .codec_dai_name = "snd-soc-dummy-dai", |
| 339 | .codec_name = "snd-soc-dummy", |
| 340 | .platform_name = "sst-mfld-platform", |
| 341 | .ignore_suspend = 1, |
| 342 | .dynamic = 1, |
| 343 | .dpcm_playback = 1, |
| 344 | .dpcm_capture = 1, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 345 | .ops = &byt_rt5640_aif1_ops, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 346 | }, |
Pierre-Louis Bossart | d35eb96 | 2015-12-17 20:35:45 -0600 | [diff] [blame] | 347 | [MERR_DPCM_DEEP_BUFFER] = { |
| 348 | .name = "Deep-Buffer Audio Port", |
| 349 | .stream_name = "Deep-Buffer Audio", |
| 350 | .cpu_dai_name = "deepbuffer-cpu-dai", |
| 351 | .codec_dai_name = "snd-soc-dummy-dai", |
| 352 | .codec_name = "snd-soc-dummy", |
| 353 | .platform_name = "sst-mfld-platform", |
| 354 | .ignore_suspend = 1, |
| 355 | .nonatomic = true, |
| 356 | .dynamic = 1, |
| 357 | .dpcm_playback = 1, |
| 358 | .ops = &byt_rt5640_aif1_ops, |
| 359 | }, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 360 | [MERR_DPCM_COMPR] = { |
| 361 | .name = "Baytrail Compressed Port", |
| 362 | .stream_name = "Baytrail Compress", |
| 363 | .cpu_dai_name = "compress-cpu-dai", |
| 364 | .codec_dai_name = "snd-soc-dummy-dai", |
| 365 | .codec_name = "snd-soc-dummy", |
| 366 | .platform_name = "sst-mfld-platform", |
| 367 | }, |
| 368 | /* back ends */ |
| 369 | { |
| 370 | .name = "SSP2-Codec", |
Mengdong Lin | 2f0ad49 | 2016-04-19 13:12:35 +0800 | [diff] [blame] | 371 | .id = 1, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 372 | .cpu_dai_name = "ssp2-port", |
| 373 | .platform_name = "sst-mfld-platform", |
| 374 | .no_pcm = 1, |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame^] | 375 | .codec_dai_name = "rt5640-aif1", /* changed w/ quirk */ |
Pierre-Louis Bossart | 7762ef4 | 2016-01-04 17:20:29 -0600 | [diff] [blame] | 376 | .codec_name = "i2c-10EC5640:00", /* overwritten with HID */ |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 377 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 378 | | SND_SOC_DAIFMT_CBS_CFS, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 379 | .be_hw_params_fixup = byt_rt5640_codec_fixup, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 380 | .ignore_suspend = 1, |
| 381 | .dpcm_playback = 1, |
| 382 | .dpcm_capture = 1, |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 383 | .init = byt_rt5640_init, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 384 | .ops = &byt_rt5640_be_ssp2_ops, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 385 | }, |
| 386 | }; |
| 387 | |
| 388 | /* SoC card */ |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 389 | static struct snd_soc_card byt_rt5640_card = { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 390 | .name = "bytcr-rt5640", |
Axel Lin | 54d8697 | 2015-08-21 20:59:21 +0800 | [diff] [blame] | 391 | .owner = THIS_MODULE, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 392 | .dai_link = byt_rt5640_dais, |
| 393 | .num_links = ARRAY_SIZE(byt_rt5640_dais), |
| 394 | .dapm_widgets = byt_rt5640_widgets, |
| 395 | .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets), |
| 396 | .dapm_routes = byt_rt5640_audio_map, |
| 397 | .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map), |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 398 | .fully_routed = true, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 399 | }; |
| 400 | |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 401 | 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^] | 402 | static char byt_rt5640_codec_aif_name[12]; /* = "rt5640-aif[1|2]" */ |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 403 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 404 | static int snd_byt_rt5640_mc_probe(struct platform_device *pdev) |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 405 | { |
| 406 | int ret_val = 0; |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 407 | struct sst_acpi_mach *mach; |
Pierre-Louis Bossart | a232b96 | 2016-03-03 21:36:38 -0600 | [diff] [blame] | 408 | const char *i2c_name = NULL; |
| 409 | int i; |
| 410 | int dai_index; |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 411 | |
| 412 | /* register the soc card */ |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 413 | byt_rt5640_card.dev = &pdev->dev; |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 414 | mach = byt_rt5640_card.dev->platform_data; |
| 415 | |
Pierre-Louis Bossart | a232b96 | 2016-03-03 21:36:38 -0600 | [diff] [blame] | 416 | /* fix index of codec dai */ |
| 417 | dai_index = MERR_DPCM_COMPR + 1; |
| 418 | for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) { |
| 419 | if (!strcmp(byt_rt5640_dais[i].codec_name, "i2c-10EC5640:00")) { |
| 420 | dai_index = i; |
| 421 | break; |
| 422 | } |
| 423 | } |
| 424 | |
Pierre-Louis Bossart | caf94ed | 2016-01-04 17:20:28 -0600 | [diff] [blame] | 425 | /* fixup codec name based on HID */ |
Pierre-Louis Bossart | a232b96 | 2016-03-03 21:36:38 -0600 | [diff] [blame] | 426 | i2c_name = sst_acpi_find_name_from_hid(mach->id); |
| 427 | if (i2c_name != NULL) { |
| 428 | snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name), |
| 429 | "%s%s", "i2c-", i2c_name); |
| 430 | |
| 431 | byt_rt5640_dais[dai_index].codec_name = byt_rt5640_codec_name; |
| 432 | } |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 433 | |
Pierre-Louis Bossart | ab738e4 | 2016-03-03 21:36:37 -0600 | [diff] [blame] | 434 | /* check quirks before creating card */ |
| 435 | dmi_check_system(byt_rt5640_quirk_table); |
| 436 | |
Pierre-Louis Bossart | 89b8907 | 2016-08-12 16:27:50 -0500 | [diff] [blame^] | 437 | if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) { |
| 438 | |
| 439 | /* fixup codec aif name */ |
| 440 | snprintf(byt_rt5640_codec_aif_name, |
| 441 | sizeof(byt_rt5640_codec_aif_name), |
| 442 | "%s", "rt5640-aif2"); |
| 443 | |
| 444 | byt_rt5640_dais[dai_index].codec_dai_name = |
| 445 | byt_rt5640_codec_aif_name; |
| 446 | } |
| 447 | |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 448 | ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card); |
| 449 | |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 450 | if (ret_val) { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 451 | dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n", |
| 452 | ret_val); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 453 | return ret_val; |
| 454 | } |
Pierre-Louis Bossart | 9fd5747 | 2015-12-17 20:35:42 -0600 | [diff] [blame] | 455 | platform_set_drvdata(pdev, &byt_rt5640_card); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 456 | return ret_val; |
| 457 | } |
| 458 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 459 | static struct platform_driver snd_byt_rt5640_mc_driver = { |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 460 | .driver = { |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 461 | .name = "bytcr_rt5640", |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 462 | .pm = &snd_soc_pm_ops, |
| 463 | }, |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 464 | .probe = snd_byt_rt5640_mc_probe, |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 465 | }; |
| 466 | |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 467 | module_platform_driver(snd_byt_rt5640_mc_driver); |
Subhransu S. Prusty | 996cc84 | 2014-11-19 15:13:27 +0530 | [diff] [blame] | 468 | |
| 469 | MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver"); |
| 470 | MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>"); |
| 471 | MODULE_LICENSE("GPL v2"); |
Pierre-Louis Bossart | a2d5563 | 2015-12-17 20:35:41 -0600 | [diff] [blame] | 472 | MODULE_ALIAS("platform:bytcr_rt5640"); |