Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * cht-bsw-rt5645.c - ASoc Machine driver for Intel Cherryview-based platforms |
| 3 | * Cherrytrail and Braswell, with RT5645 codec. |
| 4 | * |
| 5 | * Copyright (C) 2015 Intel Corp |
| 6 | * Author: Fang, Yang A <yang.a.fang@intel.com> |
| 7 | * N,Harshapriya <harshapriya.n@intel.com> |
| 8 | * This file is modified from cht_bsw_rt5672.c |
| 9 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; version 2 of the License. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 24 | #include <linux/acpi.h> |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/slab.h> |
Pierre-Louis Bossart | 09f78f1 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 27 | #include <asm/cpu_device_id.h> |
| 28 | #include <asm/platform_sst_audio.h> |
| 29 | #include <linux/clk.h> |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 30 | #include <sound/pcm.h> |
| 31 | #include <sound/pcm_params.h> |
| 32 | #include <sound/soc.h> |
| 33 | #include <sound/jack.h> |
Jie Yang | e56c72d | 2015-04-02 15:37:02 +0800 | [diff] [blame] | 34 | #include "../../codecs/rt5645.h" |
Jie Yang | b97169d | 2015-04-02 15:37:04 +0800 | [diff] [blame] | 35 | #include "../atom/sst-atom-controls.h" |
Vinod Koul | 07d5c17 | 2016-07-08 15:39:51 +0530 | [diff] [blame] | 36 | #include "../common/sst-acpi.h" |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 37 | |
| 38 | #define CHT_PLAT_CLK_3_HZ 19200000 |
| 39 | #define CHT_CODEC_DAI "rt5645-aif1" |
| 40 | |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 41 | struct cht_acpi_card { |
| 42 | char *codec_id; |
| 43 | int codec_type; |
| 44 | struct snd_soc_card *soc_card; |
| 45 | }; |
| 46 | |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 47 | struct cht_mc_private { |
Fang, Yang A | 673c4f8 | 2015-05-05 16:55:34 -0700 | [diff] [blame] | 48 | struct snd_soc_jack jack; |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 49 | struct cht_acpi_card *acpi_card; |
Takashi Iwai | d61a969 | 2016-11-22 18:11:08 +0100 | [diff] [blame] | 50 | char codec_name[16]; |
Pierre-Louis Bossart | 09f78f1 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 51 | struct clk *mclk; |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card) |
| 55 | { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 56 | struct snd_soc_pcm_runtime *rtd; |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 57 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 58 | list_for_each_entry(rtd, &card->rtd_list, list) { |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 59 | if (!strncmp(rtd->codec_dai->name, CHT_CODEC_DAI, |
| 60 | strlen(CHT_CODEC_DAI))) |
| 61 | return rtd->codec_dai; |
| 62 | } |
| 63 | return NULL; |
| 64 | } |
| 65 | |
| 66 | static int platform_clock_control(struct snd_soc_dapm_widget *w, |
| 67 | struct snd_kcontrol *k, int event) |
| 68 | { |
| 69 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 70 | struct snd_soc_card *card = dapm->card; |
| 71 | struct snd_soc_dai *codec_dai; |
Pierre-Louis Bossart | 09f78f1 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 72 | struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card); |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 73 | int ret; |
| 74 | |
| 75 | codec_dai = cht_get_codec_dai(card); |
| 76 | if (!codec_dai) { |
| 77 | dev_err(card->dev, "Codec dai not found; Unable to set platform clock\n"); |
| 78 | return -EIO; |
| 79 | } |
| 80 | |
Pierre-Louis Bossart | 09f78f1 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 81 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
| 82 | if (ctx->mclk) { |
| 83 | ret = clk_prepare_enable(ctx->mclk); |
| 84 | if (ret < 0) { |
| 85 | dev_err(card->dev, |
| 86 | "could not configure MCLK state"); |
| 87 | return ret; |
| 88 | } |
| 89 | } |
| 90 | } else { |
| 91 | /* Set codec sysclk source to its internal clock because codec PLL will |
| 92 | * be off when idle and MCLK will also be off when codec is |
| 93 | * runtime suspended. Codec needs clock for jack detection and button |
| 94 | * press. MCLK is turned off with clock framework or ACPI. |
| 95 | */ |
| 96 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5645_SCLK_S_RCCLK, |
| 97 | 48000 * 512, SND_SOC_CLOCK_IN); |
| 98 | if (ret < 0) { |
| 99 | dev_err(card->dev, "can't set codec sysclk: %d\n", ret); |
| 100 | return ret; |
| 101 | } |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 102 | |
Pierre-Louis Bossart | 09f78f1 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 103 | if (ctx->mclk) |
| 104 | clk_disable_unprepare(ctx->mclk); |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static const struct snd_soc_dapm_widget cht_dapm_widgets[] = { |
| 111 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 112 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 113 | SND_SOC_DAPM_MIC("Int Mic", NULL), |
Hans de Goede | c5ae3c6 | 2018-01-02 19:53:14 +0100 | [diff] [blame] | 114 | SND_SOC_DAPM_MIC("Int Analog Mic", NULL), |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 115 | SND_SOC_DAPM_SPK("Ext Spk", NULL), |
| 116 | SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, |
Pierre-Louis Bossart | 09f78f1 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 117 | platform_clock_control, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 118 | }; |
| 119 | |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 120 | static const struct snd_soc_dapm_route cht_rt5645_audio_map[] = { |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 121 | {"IN1P", NULL, "Headset Mic"}, |
| 122 | {"IN1N", NULL, "Headset Mic"}, |
| 123 | {"DMIC L1", NULL, "Int Mic"}, |
| 124 | {"DMIC R1", NULL, "Int Mic"}, |
Hans de Goede | c5ae3c6 | 2018-01-02 19:53:14 +0100 | [diff] [blame] | 125 | {"IN2P", NULL, "Int Analog Mic"}, |
| 126 | {"IN2N", NULL, "Int Analog Mic"}, |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 127 | {"Headphone", NULL, "HPOL"}, |
| 128 | {"Headphone", NULL, "HPOR"}, |
| 129 | {"Ext Spk", NULL, "SPOL"}, |
| 130 | {"Ext Spk", NULL, "SPOR"}, |
| 131 | {"AIF1 Playback", NULL, "ssp2 Tx"}, |
| 132 | {"ssp2 Tx", NULL, "codec_out0"}, |
| 133 | {"ssp2 Tx", NULL, "codec_out1"}, |
| 134 | {"codec_in0", NULL, "ssp2 Rx" }, |
| 135 | {"codec_in1", NULL, "ssp2 Rx" }, |
| 136 | {"ssp2 Rx", NULL, "AIF1 Capture"}, |
| 137 | {"Headphone", NULL, "Platform Clock"}, |
| 138 | {"Headset Mic", NULL, "Platform Clock"}, |
| 139 | {"Int Mic", NULL, "Platform Clock"}, |
Hans de Goede | c5ae3c6 | 2018-01-02 19:53:14 +0100 | [diff] [blame] | 140 | {"Int Analog Mic", NULL, "Platform Clock"}, |
| 141 | {"Int Analog Mic", NULL, "micbias1"}, |
| 142 | {"Int Analog Mic", NULL, "micbias2"}, |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 143 | {"Ext Spk", NULL, "Platform Clock"}, |
| 144 | }; |
| 145 | |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 146 | static const struct snd_soc_dapm_route cht_rt5650_audio_map[] = { |
| 147 | {"IN1P", NULL, "Headset Mic"}, |
| 148 | {"IN1N", NULL, "Headset Mic"}, |
| 149 | {"DMIC L2", NULL, "Int Mic"}, |
| 150 | {"DMIC R2", NULL, "Int Mic"}, |
| 151 | {"Headphone", NULL, "HPOL"}, |
| 152 | {"Headphone", NULL, "HPOR"}, |
| 153 | {"Ext Spk", NULL, "SPOL"}, |
| 154 | {"Ext Spk", NULL, "SPOR"}, |
| 155 | {"AIF1 Playback", NULL, "ssp2 Tx"}, |
| 156 | {"ssp2 Tx", NULL, "codec_out0"}, |
| 157 | {"ssp2 Tx", NULL, "codec_out1"}, |
| 158 | {"codec_in0", NULL, "ssp2 Rx" }, |
| 159 | {"codec_in1", NULL, "ssp2 Rx" }, |
| 160 | {"ssp2 Rx", NULL, "AIF1 Capture"}, |
| 161 | {"Headphone", NULL, "Platform Clock"}, |
| 162 | {"Headset Mic", NULL, "Platform Clock"}, |
| 163 | {"Int Mic", NULL, "Platform Clock"}, |
| 164 | {"Ext Spk", NULL, "Platform Clock"}, |
| 165 | }; |
| 166 | |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 167 | static const struct snd_kcontrol_new cht_mc_controls[] = { |
| 168 | SOC_DAPM_PIN_SWITCH("Headphone"), |
| 169 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
| 170 | SOC_DAPM_PIN_SWITCH("Int Mic"), |
Hans de Goede | c5ae3c6 | 2018-01-02 19:53:14 +0100 | [diff] [blame] | 171 | SOC_DAPM_PIN_SWITCH("Int Analog Mic"), |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 172 | SOC_DAPM_PIN_SWITCH("Ext Spk"), |
| 173 | }; |
| 174 | |
Carlo Caione | 2303b32 | 2016-02-16 22:27:19 +0100 | [diff] [blame] | 175 | static struct snd_soc_jack_pin cht_bsw_jack_pins[] = { |
| 176 | { |
| 177 | .pin = "Headphone", |
| 178 | .mask = SND_JACK_HEADPHONE, |
| 179 | }, |
| 180 | { |
| 181 | .pin = "Headset Mic", |
| 182 | .mask = SND_JACK_MICROPHONE, |
| 183 | }, |
| 184 | }; |
| 185 | |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 186 | static int cht_aif1_hw_params(struct snd_pcm_substream *substream, |
| 187 | struct snd_pcm_hw_params *params) |
| 188 | { |
| 189 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 190 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 191 | int ret; |
| 192 | |
| 193 | /* set codec PLL source to the 19.2MHz platform clock (MCLK) */ |
| 194 | ret = snd_soc_dai_set_pll(codec_dai, 0, RT5645_PLL1_S_MCLK, |
| 195 | CHT_PLAT_CLK_3_HZ, params_rate(params) * 512); |
| 196 | if (ret < 0) { |
| 197 | dev_err(rtd->dev, "can't set codec pll: %d\n", ret); |
| 198 | return ret; |
| 199 | } |
| 200 | |
| 201 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5645_SCLK_S_PLL1, |
| 202 | params_rate(params) * 512, SND_SOC_CLOCK_IN); |
| 203 | if (ret < 0) { |
| 204 | dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret); |
| 205 | return ret; |
| 206 | } |
| 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | static int cht_codec_init(struct snd_soc_pcm_runtime *runtime) |
| 212 | { |
| 213 | int ret; |
Fang, Yang A | 673c4f8 | 2015-05-05 16:55:34 -0700 | [diff] [blame] | 214 | int jack_type; |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 215 | struct snd_soc_codec *codec = runtime->codec; |
| 216 | struct snd_soc_dai *codec_dai = runtime->codec_dai; |
| 217 | struct cht_mc_private *ctx = snd_soc_card_get_drvdata(runtime->card); |
| 218 | |
| 219 | /* Select clk_i2s1_asrc as ASRC clock source */ |
| 220 | rt5645_sel_asrc_clk_src(codec, |
| 221 | RT5645_DA_STEREO_FILTER | |
| 222 | RT5645_DA_MONO_L_FILTER | |
| 223 | RT5645_DA_MONO_R_FILTER | |
| 224 | RT5645_AD_STEREO_FILTER, |
| 225 | RT5645_CLK_SEL_I2S1_ASRC); |
| 226 | |
| 227 | /* TDM 4 slots 24 bit, set Rx & Tx bitmask to 4 active slots */ |
| 228 | ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0xF, 4, 24); |
| 229 | if (ret < 0) { |
| 230 | dev_err(runtime->dev, "can't set codec TDM slot %d\n", ret); |
| 231 | return ret; |
| 232 | } |
| 233 | |
Fang, Yang A | 673c4f8 | 2015-05-05 16:55:34 -0700 | [diff] [blame] | 234 | if (ctx->acpi_card->codec_type == CODEC_TYPE_RT5650) |
| 235 | jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE | |
| 236 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | |
| 237 | SND_JACK_BTN_2 | SND_JACK_BTN_3; |
| 238 | else |
| 239 | jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE; |
| 240 | |
Carlo Caione | 2303b32 | 2016-02-16 22:27:19 +0100 | [diff] [blame] | 241 | ret = snd_soc_card_jack_new(runtime->card, "Headset", |
Fang, Yang A | 673c4f8 | 2015-05-05 16:55:34 -0700 | [diff] [blame] | 242 | jack_type, &ctx->jack, |
Carlo Caione | 2303b32 | 2016-02-16 22:27:19 +0100 | [diff] [blame] | 243 | cht_bsw_jack_pins, ARRAY_SIZE(cht_bsw_jack_pins)); |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 244 | if (ret) { |
Fang, Yang A | 673c4f8 | 2015-05-05 16:55:34 -0700 | [diff] [blame] | 245 | dev_err(runtime->dev, "Headset jack creation failed %d\n", ret); |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 246 | return ret; |
| 247 | } |
| 248 | |
Fang, Yang A | 673c4f8 | 2015-05-05 16:55:34 -0700 | [diff] [blame] | 249 | rt5645_set_jack_detect(codec, &ctx->jack, &ctx->jack, &ctx->jack); |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 250 | |
Pierre-Louis Bossart | 09f78f1 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 251 | if (ctx->mclk) { |
| 252 | /* |
| 253 | * The firmware might enable the clock at |
| 254 | * boot (this information may or may not |
| 255 | * be reflected in the enable clock register). |
| 256 | * To change the rate we must disable the clock |
| 257 | * first to cover these cases. Due to common |
| 258 | * clock framework restrictions that do not allow |
| 259 | * to disable a clock that has not been enabled, |
| 260 | * we need to enable the clock first. |
| 261 | */ |
| 262 | ret = clk_prepare_enable(ctx->mclk); |
| 263 | if (!ret) |
| 264 | clk_disable_unprepare(ctx->mclk); |
| 265 | |
| 266 | ret = clk_set_rate(ctx->mclk, CHT_PLAT_CLK_3_HZ); |
| 267 | |
| 268 | if (ret) |
| 269 | dev_err(runtime->dev, "unable to set MCLK rate\n"); |
| 270 | } |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 271 | return ret; |
| 272 | } |
| 273 | |
| 274 | static int cht_codec_fixup(struct snd_soc_pcm_runtime *rtd, |
| 275 | struct snd_pcm_hw_params *params) |
| 276 | { |
| 277 | struct snd_interval *rate = hw_param_interval(params, |
| 278 | SNDRV_PCM_HW_PARAM_RATE); |
| 279 | struct snd_interval *channels = hw_param_interval(params, |
| 280 | SNDRV_PCM_HW_PARAM_CHANNELS); |
| 281 | |
| 282 | /* The DSP will covert the FE rate to 48k, stereo, 24bits */ |
| 283 | rate->min = rate->max = 48000; |
| 284 | channels->min = channels->max = 2; |
| 285 | |
| 286 | /* set SSP2 to 24-bit */ |
Fang, Yang A | 369a9f5 | 2015-02-09 00:18:12 -0800 | [diff] [blame] | 287 | params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 288 | return 0; |
| 289 | } |
| 290 | |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 291 | static int cht_aif1_startup(struct snd_pcm_substream *substream) |
| 292 | { |
Lars-Peter Clausen | 3d6a76c | 2015-10-18 15:39:32 +0200 | [diff] [blame] | 293 | return snd_pcm_hw_constraint_single(substream->runtime, |
| 294 | SNDRV_PCM_HW_PARAM_RATE, 48000); |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static struct snd_soc_ops cht_aif1_ops = { |
| 298 | .startup = cht_aif1_startup, |
| 299 | }; |
| 300 | |
| 301 | static struct snd_soc_ops cht_be_ssp2_ops = { |
| 302 | .hw_params = cht_aif1_hw_params, |
| 303 | }; |
| 304 | |
| 305 | static struct snd_soc_dai_link cht_dailink[] = { |
| 306 | [MERR_DPCM_AUDIO] = { |
| 307 | .name = "Audio Port", |
| 308 | .stream_name = "Audio", |
| 309 | .cpu_dai_name = "media-cpu-dai", |
| 310 | .codec_dai_name = "snd-soc-dummy-dai", |
| 311 | .codec_name = "snd-soc-dummy", |
| 312 | .platform_name = "sst-mfld-platform", |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 313 | .nonatomic = true, |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 314 | .dynamic = 1, |
| 315 | .dpcm_playback = 1, |
| 316 | .dpcm_capture = 1, |
| 317 | .ops = &cht_aif1_ops, |
| 318 | }, |
Pierre-Louis Bossart | d35eb96 | 2015-12-17 20:35:45 -0600 | [diff] [blame] | 319 | [MERR_DPCM_DEEP_BUFFER] = { |
| 320 | .name = "Deep-Buffer Audio Port", |
| 321 | .stream_name = "Deep-Buffer Audio", |
| 322 | .cpu_dai_name = "deepbuffer-cpu-dai", |
| 323 | .codec_dai_name = "snd-soc-dummy-dai", |
| 324 | .codec_name = "snd-soc-dummy", |
| 325 | .platform_name = "sst-mfld-platform", |
| 326 | .nonatomic = true, |
| 327 | .dynamic = 1, |
| 328 | .dpcm_playback = 1, |
| 329 | .ops = &cht_aif1_ops, |
| 330 | }, |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 331 | [MERR_DPCM_COMPR] = { |
| 332 | .name = "Compressed Port", |
| 333 | .stream_name = "Compress", |
| 334 | .cpu_dai_name = "compress-cpu-dai", |
| 335 | .codec_dai_name = "snd-soc-dummy-dai", |
| 336 | .codec_name = "snd-soc-dummy", |
| 337 | .platform_name = "sst-mfld-platform", |
| 338 | }, |
| 339 | /* CODEC<->CODEC link */ |
| 340 | /* back ends */ |
| 341 | { |
| 342 | .name = "SSP2-Codec", |
Mengdong Lin | 2f0ad49 | 2016-04-19 13:12:35 +0800 | [diff] [blame] | 343 | .id = 1, |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 344 | .cpu_dai_name = "ssp2-port", |
| 345 | .platform_name = "sst-mfld-platform", |
| 346 | .no_pcm = 1, |
| 347 | .codec_dai_name = "rt5645-aif1", |
| 348 | .codec_name = "i2c-10EC5645:00", |
| 349 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF |
| 350 | | SND_SOC_DAIFMT_CBS_CFS, |
| 351 | .init = cht_codec_init, |
| 352 | .be_hw_params_fixup = cht_codec_fixup, |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 353 | .nonatomic = true, |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 354 | .dpcm_playback = 1, |
| 355 | .dpcm_capture = 1, |
| 356 | .ops = &cht_be_ssp2_ops, |
| 357 | }, |
| 358 | }; |
| 359 | |
| 360 | /* SoC card */ |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 361 | static struct snd_soc_card snd_soc_card_chtrt5645 = { |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 362 | .name = "chtrt5645", |
Axel Lin | 54d8697 | 2015-08-21 20:59:21 +0800 | [diff] [blame] | 363 | .owner = THIS_MODULE, |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 364 | .dai_link = cht_dailink, |
| 365 | .num_links = ARRAY_SIZE(cht_dailink), |
| 366 | .dapm_widgets = cht_dapm_widgets, |
| 367 | .num_dapm_widgets = ARRAY_SIZE(cht_dapm_widgets), |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 368 | .dapm_routes = cht_rt5645_audio_map, |
| 369 | .num_dapm_routes = ARRAY_SIZE(cht_rt5645_audio_map), |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 370 | .controls = cht_mc_controls, |
| 371 | .num_controls = ARRAY_SIZE(cht_mc_controls), |
| 372 | }; |
| 373 | |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 374 | static struct snd_soc_card snd_soc_card_chtrt5650 = { |
| 375 | .name = "chtrt5650", |
Axel Lin | 54d8697 | 2015-08-21 20:59:21 +0800 | [diff] [blame] | 376 | .owner = THIS_MODULE, |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 377 | .dai_link = cht_dailink, |
| 378 | .num_links = ARRAY_SIZE(cht_dailink), |
| 379 | .dapm_widgets = cht_dapm_widgets, |
| 380 | .num_dapm_widgets = ARRAY_SIZE(cht_dapm_widgets), |
| 381 | .dapm_routes = cht_rt5650_audio_map, |
| 382 | .num_dapm_routes = ARRAY_SIZE(cht_rt5650_audio_map), |
| 383 | .controls = cht_mc_controls, |
| 384 | .num_controls = ARRAY_SIZE(cht_mc_controls), |
| 385 | }; |
| 386 | |
| 387 | static struct cht_acpi_card snd_soc_cards[] = { |
Vinod Koul | 07d5c17 | 2016-07-08 15:39:51 +0530 | [diff] [blame] | 388 | {"10EC5640", CODEC_TYPE_RT5645, &snd_soc_card_chtrt5645}, |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 389 | {"10EC5645", CODEC_TYPE_RT5645, &snd_soc_card_chtrt5645}, |
| 390 | {"10EC5650", CODEC_TYPE_RT5650, &snd_soc_card_chtrt5650}, |
| 391 | }; |
| 392 | |
Vinod Koul | 07d5c17 | 2016-07-08 15:39:51 +0530 | [diff] [blame] | 393 | static char cht_rt5640_codec_name[16]; /* i2c-<HID>:00 with HID being 8 chars */ |
| 394 | |
Pierre-Louis Bossart | 09f78f1 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 395 | static bool is_valleyview(void) |
| 396 | { |
| 397 | static const struct x86_cpu_id cpu_ids[] = { |
| 398 | { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */ |
| 399 | {} |
| 400 | }; |
| 401 | |
| 402 | if (!x86_match_cpu(cpu_ids)) |
| 403 | return false; |
| 404 | return true; |
| 405 | } |
| 406 | |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 407 | static int snd_cht_mc_probe(struct platform_device *pdev) |
| 408 | { |
| 409 | int ret_val = 0; |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 410 | int i; |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 411 | struct cht_mc_private *drv; |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 412 | struct snd_soc_card *card = snd_soc_cards[0].soc_card; |
Vinod Koul | 07d5c17 | 2016-07-08 15:39:51 +0530 | [diff] [blame] | 413 | struct sst_acpi_mach *mach; |
| 414 | const char *i2c_name = NULL; |
Vinod Koul | 5d554ea | 2016-07-08 18:30:17 +0530 | [diff] [blame] | 415 | int dai_index = 0; |
Pierre-Louis Bossart | 584f431 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 416 | bool found = false; |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 417 | |
| 418 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_ATOMIC); |
| 419 | if (!drv) |
| 420 | return -ENOMEM; |
| 421 | |
Pierre-Louis Bossart | 584f431 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 422 | mach = (&pdev->dev)->platform_data; |
| 423 | |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 424 | for (i = 0; i < ARRAY_SIZE(snd_soc_cards); i++) { |
Pierre-Louis Bossart | 584f431 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 425 | if (acpi_dev_found(snd_soc_cards[i].codec_id) && |
| 426 | (!strncmp(snd_soc_cards[i].codec_id, mach->id, 8))) { |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 427 | dev_dbg(&pdev->dev, |
| 428 | "found codec %s\n", snd_soc_cards[i].codec_id); |
| 429 | card = snd_soc_cards[i].soc_card; |
| 430 | drv->acpi_card = &snd_soc_cards[i]; |
Pierre-Louis Bossart | 584f431 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 431 | found = true; |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 432 | break; |
| 433 | } |
| 434 | } |
Pierre-Louis Bossart | 584f431 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 435 | |
| 436 | if (!found) { |
| 437 | dev_err(&pdev->dev, "No matching HID found in supported list\n"); |
| 438 | return -ENODEV; |
| 439 | } |
| 440 | |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 441 | card->dev = &pdev->dev; |
Takashi Iwai | d61a969 | 2016-11-22 18:11:08 +0100 | [diff] [blame] | 442 | sprintf(drv->codec_name, "i2c-%s:00", drv->acpi_card->codec_id); |
Carlo Caione | c8560b7 | 2016-02-23 09:50:20 +0100 | [diff] [blame] | 443 | |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 444 | /* set correct codec name */ |
Carlo Caione | c8560b7 | 2016-02-23 09:50:20 +0100 | [diff] [blame] | 445 | for (i = 0; i < ARRAY_SIZE(cht_dailink); i++) |
Vinod Koul | 07d5c17 | 2016-07-08 15:39:51 +0530 | [diff] [blame] | 446 | if (!strcmp(card->dai_link[i].codec_name, "i2c-10EC5645:00")) { |
Takashi Iwai | d61a969 | 2016-11-22 18:11:08 +0100 | [diff] [blame] | 447 | card->dai_link[i].codec_name = drv->codec_name; |
Vinod Koul | 07d5c17 | 2016-07-08 15:39:51 +0530 | [diff] [blame] | 448 | dai_index = i; |
| 449 | } |
| 450 | |
| 451 | /* fixup codec name based on HID */ |
| 452 | i2c_name = sst_acpi_find_name_from_hid(mach->id); |
| 453 | if (i2c_name != NULL) { |
| 454 | snprintf(cht_rt5640_codec_name, sizeof(cht_rt5640_codec_name), |
| 455 | "%s%s", "i2c-", i2c_name); |
| 456 | cht_dailink[dai_index].codec_name = cht_rt5640_codec_name; |
| 457 | } |
Carlo Caione | c8560b7 | 2016-02-23 09:50:20 +0100 | [diff] [blame] | 458 | |
Pierre-Louis Bossart | 09f78f1 | 2017-04-04 19:32:29 +0000 | [diff] [blame] | 459 | if (is_valleyview()) { |
| 460 | drv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3"); |
| 461 | if (IS_ERR(drv->mclk)) { |
| 462 | dev_err(&pdev->dev, |
| 463 | "Failed to get MCLK from pmc_plt_clk_3: %ld\n", |
| 464 | PTR_ERR(drv->mclk)); |
| 465 | return PTR_ERR(drv->mclk); |
| 466 | } |
| 467 | } |
| 468 | |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 469 | snd_soc_card_set_drvdata(card, drv); |
| 470 | ret_val = devm_snd_soc_register_card(&pdev->dev, card); |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 471 | if (ret_val) { |
| 472 | dev_err(&pdev->dev, |
| 473 | "snd_soc_register_card failed %d\n", ret_val); |
| 474 | return ret_val; |
| 475 | } |
Fang, Yang A | c4ba51b | 2015-04-23 10:23:02 -0700 | [diff] [blame] | 476 | platform_set_drvdata(pdev, card); |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 477 | return ret_val; |
| 478 | } |
| 479 | |
| 480 | static struct platform_driver snd_cht_mc_driver = { |
| 481 | .driver = { |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 482 | .name = "cht-bsw-rt5645", |
Fang, Yang A | e18acdc | 2015-02-04 18:19:32 -0800 | [diff] [blame] | 483 | }, |
| 484 | .probe = snd_cht_mc_probe, |
| 485 | }; |
| 486 | |
| 487 | module_platform_driver(snd_cht_mc_driver) |
| 488 | |
| 489 | MODULE_DESCRIPTION("ASoC Intel(R) Braswell Machine driver"); |
| 490 | MODULE_AUTHOR("Fang, Yang A,N,Harshapriya"); |
| 491 | MODULE_LICENSE("GPL v2"); |
| 492 | MODULE_ALIAS("platform:cht-bsw-rt5645"); |