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