| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * bytcht_es8316.c - ASoc Machine driver for Intel Baytrail/Cherrytrail |
|---|
| 3 | 4 | * platforms with Everest ES8316 SoC |
|---|
| .. | .. |
|---|
| 8 | 9 | * |
|---|
| 9 | 10 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 10 | 11 | * |
|---|
| 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 | 12 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 | 13 | */ |
|---|
| 14 | +#include <linux/acpi.h> |
|---|
| 15 | +#include <linux/clk.h> |
|---|
| 16 | +#include <linux/device.h> |
|---|
| 17 | +#include <linux/dmi.h> |
|---|
| 18 | +#include <linux/gpio/consumer.h> |
|---|
| 19 | +#include <linux/i2c.h> |
|---|
| 22 | 20 | #include <linux/init.h> |
|---|
| 21 | +#include <linux/input.h> |
|---|
| 23 | 22 | #include <linux/module.h> |
|---|
| 24 | 23 | #include <linux/platform_device.h> |
|---|
| 25 | | -#include <linux/device.h> |
|---|
| 26 | 24 | #include <linux/slab.h> |
|---|
| 27 | | -#include <asm/platform_sst_audio.h> |
|---|
| 28 | | -#include <linux/clk.h> |
|---|
| 25 | +#include <sound/jack.h> |
|---|
| 29 | 26 | #include <sound/pcm.h> |
|---|
| 30 | 27 | #include <sound/pcm_params.h> |
|---|
| 31 | 28 | #include <sound/soc.h> |
|---|
| 32 | 29 | #include <sound/soc-acpi.h> |
|---|
| 33 | 30 | #include "../atom/sst-atom-controls.h" |
|---|
| 34 | | -#include "../common/sst-dsp.h" |
|---|
| 31 | +#include "../common/soc-intel-quirks.h" |
|---|
| 32 | + |
|---|
| 33 | +/* jd-inv + terminating entry */ |
|---|
| 34 | +#define MAX_NO_PROPS 2 |
|---|
| 35 | 35 | |
|---|
| 36 | 36 | struct byt_cht_es8316_private { |
|---|
| 37 | 37 | struct clk *mclk; |
|---|
| 38 | + struct snd_soc_jack jack; |
|---|
| 39 | + struct gpio_desc *speaker_en_gpio; |
|---|
| 40 | + bool speaker_en; |
|---|
| 38 | 41 | }; |
|---|
| 39 | 42 | |
|---|
| 40 | | -static const struct snd_soc_dapm_widget byt_cht_es8316_widgets[] = { |
|---|
| 41 | | - SND_SOC_DAPM_HP("Headphone", NULL), |
|---|
| 43 | +enum { |
|---|
| 44 | + BYT_CHT_ES8316_INTMIC_IN1_MAP, |
|---|
| 45 | + BYT_CHT_ES8316_INTMIC_IN2_MAP, |
|---|
| 46 | +}; |
|---|
| 42 | 47 | |
|---|
| 43 | | - /* |
|---|
| 44 | | - * The codec supports two analog microphone inputs. I have only |
|---|
| 45 | | - * tested MIC1. A DMIC route could also potentially be added |
|---|
| 46 | | - * if such functionality is found on another platform. |
|---|
| 47 | | - */ |
|---|
| 48 | | - SND_SOC_DAPM_MIC("Microphone 1", NULL), |
|---|
| 49 | | - SND_SOC_DAPM_MIC("Microphone 2", NULL), |
|---|
| 48 | +#define BYT_CHT_ES8316_MAP(quirk) ((quirk) & GENMASK(3, 0)) |
|---|
| 49 | +#define BYT_CHT_ES8316_SSP0 BIT(16) |
|---|
| 50 | +#define BYT_CHT_ES8316_MONO_SPEAKER BIT(17) |
|---|
| 51 | +#define BYT_CHT_ES8316_JD_INVERTED BIT(18) |
|---|
| 52 | + |
|---|
| 53 | +static unsigned long quirk; |
|---|
| 54 | + |
|---|
| 55 | +static int quirk_override = -1; |
|---|
| 56 | +module_param_named(quirk, quirk_override, int, 0444); |
|---|
| 57 | +MODULE_PARM_DESC(quirk, "Board-specific quirk override"); |
|---|
| 58 | + |
|---|
| 59 | +static void log_quirks(struct device *dev) |
|---|
| 60 | +{ |
|---|
| 61 | + if (BYT_CHT_ES8316_MAP(quirk) == BYT_CHT_ES8316_INTMIC_IN1_MAP) |
|---|
| 62 | + dev_info(dev, "quirk IN1_MAP enabled"); |
|---|
| 63 | + if (BYT_CHT_ES8316_MAP(quirk) == BYT_CHT_ES8316_INTMIC_IN2_MAP) |
|---|
| 64 | + dev_info(dev, "quirk IN2_MAP enabled"); |
|---|
| 65 | + if (quirk & BYT_CHT_ES8316_SSP0) |
|---|
| 66 | + dev_info(dev, "quirk SSP0 enabled"); |
|---|
| 67 | + if (quirk & BYT_CHT_ES8316_MONO_SPEAKER) |
|---|
| 68 | + dev_info(dev, "quirk MONO_SPEAKER enabled\n"); |
|---|
| 69 | + if (quirk & BYT_CHT_ES8316_JD_INVERTED) |
|---|
| 70 | + dev_info(dev, "quirk JD_INVERTED enabled\n"); |
|---|
| 71 | +} |
|---|
| 72 | + |
|---|
| 73 | +static int byt_cht_es8316_speaker_power_event(struct snd_soc_dapm_widget *w, |
|---|
| 74 | + struct snd_kcontrol *kcontrol, int event) |
|---|
| 75 | +{ |
|---|
| 76 | + struct snd_soc_card *card = w->dapm->card; |
|---|
| 77 | + struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card); |
|---|
| 78 | + |
|---|
| 79 | + if (SND_SOC_DAPM_EVENT_ON(event)) |
|---|
| 80 | + priv->speaker_en = true; |
|---|
| 81 | + else |
|---|
| 82 | + priv->speaker_en = false; |
|---|
| 83 | + |
|---|
| 84 | + gpiod_set_value_cansleep(priv->speaker_en_gpio, priv->speaker_en); |
|---|
| 85 | + |
|---|
| 86 | + return 0; |
|---|
| 87 | +} |
|---|
| 88 | + |
|---|
| 89 | +static const struct snd_soc_dapm_widget byt_cht_es8316_widgets[] = { |
|---|
| 90 | + SND_SOC_DAPM_SPK("Speaker", NULL), |
|---|
| 91 | + SND_SOC_DAPM_HP("Headphone", NULL), |
|---|
| 92 | + SND_SOC_DAPM_MIC("Headset Mic", NULL), |
|---|
| 93 | + SND_SOC_DAPM_MIC("Internal Mic", NULL), |
|---|
| 94 | + |
|---|
| 95 | + SND_SOC_DAPM_SUPPLY("Speaker Power", SND_SOC_NOPM, 0, 0, |
|---|
| 96 | + byt_cht_es8316_speaker_power_event, |
|---|
| 97 | + SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), |
|---|
| 50 | 98 | }; |
|---|
| 51 | 99 | |
|---|
| 52 | 100 | static const struct snd_soc_dapm_route byt_cht_es8316_audio_map[] = { |
|---|
| 53 | | - {"MIC1", NULL, "Microphone 1"}, |
|---|
| 54 | | - {"MIC2", NULL, "Microphone 2"}, |
|---|
| 55 | | - |
|---|
| 56 | 101 | {"Headphone", NULL, "HPOL"}, |
|---|
| 57 | 102 | {"Headphone", NULL, "HPOR"}, |
|---|
| 58 | 103 | |
|---|
| 104 | + /* |
|---|
| 105 | + * There is no separate speaker output instead the speakers are muxed to |
|---|
| 106 | + * the HP outputs. The mux is controlled by the "Speaker Power" supply. |
|---|
| 107 | + */ |
|---|
| 108 | + {"Speaker", NULL, "HPOL"}, |
|---|
| 109 | + {"Speaker", NULL, "HPOR"}, |
|---|
| 110 | + {"Speaker", NULL, "Speaker Power"}, |
|---|
| 111 | +}; |
|---|
| 112 | + |
|---|
| 113 | +static const struct snd_soc_dapm_route byt_cht_es8316_intmic_in1_map[] = { |
|---|
| 114 | + {"MIC1", NULL, "Internal Mic"}, |
|---|
| 115 | + {"MIC2", NULL, "Headset Mic"}, |
|---|
| 116 | +}; |
|---|
| 117 | + |
|---|
| 118 | +static const struct snd_soc_dapm_route byt_cht_es8316_intmic_in2_map[] = { |
|---|
| 119 | + {"MIC2", NULL, "Internal Mic"}, |
|---|
| 120 | + {"MIC1", NULL, "Headset Mic"}, |
|---|
| 121 | +}; |
|---|
| 122 | + |
|---|
| 123 | +static const struct snd_soc_dapm_route byt_cht_es8316_ssp0_map[] = { |
|---|
| 124 | + {"Playback", NULL, "ssp0 Tx"}, |
|---|
| 125 | + {"ssp0 Tx", NULL, "modem_out"}, |
|---|
| 126 | + {"modem_in", NULL, "ssp0 Rx"}, |
|---|
| 127 | + {"ssp0 Rx", NULL, "Capture"}, |
|---|
| 128 | +}; |
|---|
| 129 | + |
|---|
| 130 | +static const struct snd_soc_dapm_route byt_cht_es8316_ssp2_map[] = { |
|---|
| 59 | 131 | {"Playback", NULL, "ssp2 Tx"}, |
|---|
| 60 | 132 | {"ssp2 Tx", NULL, "codec_out0"}, |
|---|
| 61 | 133 | {"ssp2 Tx", NULL, "codec_out1"}, |
|---|
| .. | .. |
|---|
| 65 | 137 | }; |
|---|
| 66 | 138 | |
|---|
| 67 | 139 | static const struct snd_kcontrol_new byt_cht_es8316_controls[] = { |
|---|
| 140 | + SOC_DAPM_PIN_SWITCH("Speaker"), |
|---|
| 68 | 141 | SOC_DAPM_PIN_SWITCH("Headphone"), |
|---|
| 69 | | - SOC_DAPM_PIN_SWITCH("Microphone 1"), |
|---|
| 70 | | - SOC_DAPM_PIN_SWITCH("Microphone 2"), |
|---|
| 142 | + SOC_DAPM_PIN_SWITCH("Headset Mic"), |
|---|
| 143 | + SOC_DAPM_PIN_SWITCH("Internal Mic"), |
|---|
| 144 | +}; |
|---|
| 145 | + |
|---|
| 146 | +static struct snd_soc_jack_pin byt_cht_es8316_jack_pins[] = { |
|---|
| 147 | + { |
|---|
| 148 | + .pin = "Headphone", |
|---|
| 149 | + .mask = SND_JACK_HEADPHONE, |
|---|
| 150 | + }, |
|---|
| 151 | + { |
|---|
| 152 | + .pin = "Headset Mic", |
|---|
| 153 | + .mask = SND_JACK_MICROPHONE, |
|---|
| 154 | + }, |
|---|
| 71 | 155 | }; |
|---|
| 72 | 156 | |
|---|
| 73 | 157 | static int byt_cht_es8316_init(struct snd_soc_pcm_runtime *runtime) |
|---|
| 74 | 158 | { |
|---|
| 159 | + struct snd_soc_component *codec = asoc_rtd_to_codec(runtime, 0)->component; |
|---|
| 75 | 160 | struct snd_soc_card *card = runtime->card; |
|---|
| 76 | 161 | struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card); |
|---|
| 162 | + const struct snd_soc_dapm_route *custom_map; |
|---|
| 163 | + int num_routes; |
|---|
| 77 | 164 | int ret; |
|---|
| 78 | 165 | |
|---|
| 79 | 166 | card->dapm.idle_bias_off = true; |
|---|
| 167 | + |
|---|
| 168 | + switch (BYT_CHT_ES8316_MAP(quirk)) { |
|---|
| 169 | + case BYT_CHT_ES8316_INTMIC_IN1_MAP: |
|---|
| 170 | + default: |
|---|
| 171 | + custom_map = byt_cht_es8316_intmic_in1_map; |
|---|
| 172 | + num_routes = ARRAY_SIZE(byt_cht_es8316_intmic_in1_map); |
|---|
| 173 | + break; |
|---|
| 174 | + case BYT_CHT_ES8316_INTMIC_IN2_MAP: |
|---|
| 175 | + custom_map = byt_cht_es8316_intmic_in2_map; |
|---|
| 176 | + num_routes = ARRAY_SIZE(byt_cht_es8316_intmic_in2_map); |
|---|
| 177 | + break; |
|---|
| 178 | + } |
|---|
| 179 | + ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes); |
|---|
| 180 | + if (ret) |
|---|
| 181 | + return ret; |
|---|
| 182 | + |
|---|
| 183 | + if (quirk & BYT_CHT_ES8316_SSP0) { |
|---|
| 184 | + custom_map = byt_cht_es8316_ssp0_map; |
|---|
| 185 | + num_routes = ARRAY_SIZE(byt_cht_es8316_ssp0_map); |
|---|
| 186 | + } else { |
|---|
| 187 | + custom_map = byt_cht_es8316_ssp2_map; |
|---|
| 188 | + num_routes = ARRAY_SIZE(byt_cht_es8316_ssp2_map); |
|---|
| 189 | + } |
|---|
| 190 | + ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes); |
|---|
| 191 | + if (ret) |
|---|
| 192 | + return ret; |
|---|
| 80 | 193 | |
|---|
| 81 | 194 | /* |
|---|
| 82 | 195 | * The firmware might enable the clock at boot (this information |
|---|
| .. | .. |
|---|
| 98 | 211 | if (ret) |
|---|
| 99 | 212 | dev_err(card->dev, "unable to enable MCLK\n"); |
|---|
| 100 | 213 | |
|---|
| 101 | | - ret = snd_soc_dai_set_sysclk(runtime->codec_dai, 0, 19200000, |
|---|
| 214 | + ret = snd_soc_dai_set_sysclk(asoc_rtd_to_codec(runtime, 0), 0, 19200000, |
|---|
| 102 | 215 | SND_SOC_CLOCK_IN); |
|---|
| 103 | 216 | if (ret < 0) { |
|---|
| 104 | 217 | dev_err(card->dev, "can't set codec clock %d\n", ret); |
|---|
| 105 | 218 | return ret; |
|---|
| 106 | 219 | } |
|---|
| 107 | 220 | |
|---|
| 221 | + ret = snd_soc_card_jack_new(card, "Headset", |
|---|
| 222 | + SND_JACK_HEADSET | SND_JACK_BTN_0, |
|---|
| 223 | + &priv->jack, byt_cht_es8316_jack_pins, |
|---|
| 224 | + ARRAY_SIZE(byt_cht_es8316_jack_pins)); |
|---|
| 225 | + if (ret) { |
|---|
| 226 | + dev_err(card->dev, "jack creation failed %d\n", ret); |
|---|
| 227 | + return ret; |
|---|
| 228 | + } |
|---|
| 229 | + |
|---|
| 230 | + snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); |
|---|
| 231 | + snd_soc_component_set_jack(codec, &priv->jack, NULL); |
|---|
| 232 | + |
|---|
| 108 | 233 | return 0; |
|---|
| 109 | 234 | } |
|---|
| 110 | | - |
|---|
| 111 | | -static const struct snd_soc_pcm_stream byt_cht_es8316_dai_params = { |
|---|
| 112 | | - .formats = SNDRV_PCM_FMTBIT_S24_LE, |
|---|
| 113 | | - .rate_min = 48000, |
|---|
| 114 | | - .rate_max = 48000, |
|---|
| 115 | | - .channels_min = 2, |
|---|
| 116 | | - .channels_max = 2, |
|---|
| 117 | | -}; |
|---|
| 118 | 235 | |
|---|
| 119 | 236 | static int byt_cht_es8316_codec_fixup(struct snd_soc_pcm_runtime *rtd, |
|---|
| 120 | 237 | struct snd_pcm_hw_params *params) |
|---|
| .. | .. |
|---|
| 123 | 240 | SNDRV_PCM_HW_PARAM_RATE); |
|---|
| 124 | 241 | struct snd_interval *channels = hw_param_interval(params, |
|---|
| 125 | 242 | SNDRV_PCM_HW_PARAM_CHANNELS); |
|---|
| 126 | | - int ret; |
|---|
| 243 | + int ret, bits; |
|---|
| 127 | 244 | |
|---|
| 128 | 245 | /* The DSP will covert the FE rate to 48k, stereo */ |
|---|
| 129 | 246 | rate->min = rate->max = 48000; |
|---|
| 130 | 247 | channels->min = channels->max = 2; |
|---|
| 131 | 248 | |
|---|
| 132 | | - /* set SSP2 to 24-bit */ |
|---|
| 133 | | - params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); |
|---|
| 249 | + if (quirk & BYT_CHT_ES8316_SSP0) { |
|---|
| 250 | + /* set SSP0 to 16-bit */ |
|---|
| 251 | + params_set_format(params, SNDRV_PCM_FORMAT_S16_LE); |
|---|
| 252 | + bits = 16; |
|---|
| 253 | + } else { |
|---|
| 254 | + /* set SSP2 to 24-bit */ |
|---|
| 255 | + params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); |
|---|
| 256 | + bits = 24; |
|---|
| 257 | + } |
|---|
| 134 | 258 | |
|---|
| 135 | 259 | /* |
|---|
| 136 | 260 | * Default mode for SSP configuration is TDM 4 slot, override config |
|---|
| 137 | 261 | * with explicit setting to I2S 2ch 24-bit. The word length is set with |
|---|
| 138 | 262 | * dai_set_tdm_slot() since there is no other API exposed |
|---|
| 139 | 263 | */ |
|---|
| 140 | | - ret = snd_soc_dai_set_fmt(rtd->cpu_dai, |
|---|
| 264 | + ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0), |
|---|
| 141 | 265 | SND_SOC_DAIFMT_I2S | |
|---|
| 142 | 266 | SND_SOC_DAIFMT_NB_NF | |
|---|
| 143 | 267 | SND_SOC_DAIFMT_CBS_CFS |
|---|
| .. | .. |
|---|
| 147 | 271 | return ret; |
|---|
| 148 | 272 | } |
|---|
| 149 | 273 | |
|---|
| 150 | | - ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24); |
|---|
| 274 | + ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits); |
|---|
| 151 | 275 | if (ret < 0) { |
|---|
| 152 | 276 | dev_err(rtd->dev, "can't set I2S config, err %d\n", ret); |
|---|
| 153 | 277 | return ret; |
|---|
| .. | .. |
|---|
| 166 | 290 | .startup = byt_cht_es8316_aif1_startup, |
|---|
| 167 | 291 | }; |
|---|
| 168 | 292 | |
|---|
| 293 | +SND_SOC_DAILINK_DEF(dummy, |
|---|
| 294 | + DAILINK_COMP_ARRAY(COMP_DUMMY())); |
|---|
| 295 | + |
|---|
| 296 | +SND_SOC_DAILINK_DEF(media, |
|---|
| 297 | + DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai"))); |
|---|
| 298 | + |
|---|
| 299 | +SND_SOC_DAILINK_DEF(deepbuffer, |
|---|
| 300 | + DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai"))); |
|---|
| 301 | + |
|---|
| 302 | +SND_SOC_DAILINK_DEF(ssp2_port, |
|---|
| 303 | + DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port"))); |
|---|
| 304 | +SND_SOC_DAILINK_DEF(ssp2_codec, |
|---|
| 305 | + DAILINK_COMP_ARRAY(COMP_CODEC("i2c-ESSX8316:00", "ES8316 HiFi"))); |
|---|
| 306 | + |
|---|
| 307 | +SND_SOC_DAILINK_DEF(platform, |
|---|
| 308 | + DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform"))); |
|---|
| 309 | + |
|---|
| 169 | 310 | static struct snd_soc_dai_link byt_cht_es8316_dais[] = { |
|---|
| 170 | 311 | [MERR_DPCM_AUDIO] = { |
|---|
| 171 | 312 | .name = "Audio Port", |
|---|
| 172 | 313 | .stream_name = "Audio", |
|---|
| 173 | | - .cpu_dai_name = "media-cpu-dai", |
|---|
| 174 | | - .codec_dai_name = "snd-soc-dummy-dai", |
|---|
| 175 | | - .codec_name = "snd-soc-dummy", |
|---|
| 176 | | - .platform_name = "sst-mfld-platform", |
|---|
| 177 | 314 | .nonatomic = true, |
|---|
| 178 | 315 | .dynamic = 1, |
|---|
| 179 | 316 | .dpcm_playback = 1, |
|---|
| 180 | 317 | .dpcm_capture = 1, |
|---|
| 181 | 318 | .ops = &byt_cht_es8316_aif1_ops, |
|---|
| 319 | + SND_SOC_DAILINK_REG(media, dummy, platform), |
|---|
| 182 | 320 | }, |
|---|
| 183 | 321 | |
|---|
| 184 | 322 | [MERR_DPCM_DEEP_BUFFER] = { |
|---|
| 185 | 323 | .name = "Deep-Buffer Audio Port", |
|---|
| 186 | 324 | .stream_name = "Deep-Buffer Audio", |
|---|
| 187 | | - .cpu_dai_name = "deepbuffer-cpu-dai", |
|---|
| 188 | | - .codec_dai_name = "snd-soc-dummy-dai", |
|---|
| 189 | | - .codec_name = "snd-soc-dummy", |
|---|
| 190 | | - .platform_name = "sst-mfld-platform", |
|---|
| 191 | 325 | .nonatomic = true, |
|---|
| 192 | 326 | .dynamic = 1, |
|---|
| 193 | 327 | .dpcm_playback = 1, |
|---|
| 194 | 328 | .ops = &byt_cht_es8316_aif1_ops, |
|---|
| 329 | + SND_SOC_DAILINK_REG(deepbuffer, dummy, platform), |
|---|
| 195 | 330 | }, |
|---|
| 196 | 331 | |
|---|
| 197 | 332 | /* back ends */ |
|---|
| .. | .. |
|---|
| 201 | 336 | */ |
|---|
| 202 | 337 | .name = "SSP2-Codec", |
|---|
| 203 | 338 | .id = 0, |
|---|
| 204 | | - .cpu_dai_name = "ssp2-port", |
|---|
| 205 | | - .platform_name = "sst-mfld-platform", |
|---|
| 206 | 339 | .no_pcm = 1, |
|---|
| 207 | | - .codec_dai_name = "ES8316 HiFi", |
|---|
| 208 | | - .codec_name = "i2c-ESSX8316:00", |
|---|
| 209 | 340 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
|---|
| 210 | 341 | | SND_SOC_DAIFMT_CBS_CFS, |
|---|
| 211 | 342 | .be_hw_params_fixup = byt_cht_es8316_codec_fixup, |
|---|
| .. | .. |
|---|
| 213 | 344 | .dpcm_playback = 1, |
|---|
| 214 | 345 | .dpcm_capture = 1, |
|---|
| 215 | 346 | .init = byt_cht_es8316_init, |
|---|
| 347 | + SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform), |
|---|
| 216 | 348 | }, |
|---|
| 217 | 349 | }; |
|---|
| 218 | 350 | |
|---|
| 219 | 351 | |
|---|
| 220 | 352 | /* SoC card */ |
|---|
| 353 | +static char codec_name[SND_ACPI_I2C_ID_LEN]; |
|---|
| 354 | +#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES) |
|---|
| 355 | +static char long_name[50]; /* = "bytcht-es8316-*-spk-*-mic" */ |
|---|
| 356 | +#endif |
|---|
| 357 | +static char components_string[32]; /* = "cfg-spk:* cfg-mic:* */ |
|---|
| 358 | + |
|---|
| 359 | +static int byt_cht_es8316_suspend(struct snd_soc_card *card) |
|---|
| 360 | +{ |
|---|
| 361 | + struct snd_soc_component *component; |
|---|
| 362 | + |
|---|
| 363 | + for_each_card_components(card, component) { |
|---|
| 364 | + if (!strcmp(component->name, codec_name)) { |
|---|
| 365 | + dev_dbg(component->dev, "disabling jack detect before suspend\n"); |
|---|
| 366 | + snd_soc_component_set_jack(component, NULL, NULL); |
|---|
| 367 | + break; |
|---|
| 368 | + } |
|---|
| 369 | + } |
|---|
| 370 | + |
|---|
| 371 | + return 0; |
|---|
| 372 | +} |
|---|
| 373 | + |
|---|
| 374 | +static int byt_cht_es8316_resume(struct snd_soc_card *card) |
|---|
| 375 | +{ |
|---|
| 376 | + struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card); |
|---|
| 377 | + struct snd_soc_component *component; |
|---|
| 378 | + |
|---|
| 379 | + for_each_card_components(card, component) { |
|---|
| 380 | + if (!strcmp(component->name, codec_name)) { |
|---|
| 381 | + dev_dbg(component->dev, "re-enabling jack detect after resume\n"); |
|---|
| 382 | + snd_soc_component_set_jack(component, &priv->jack, NULL); |
|---|
| 383 | + break; |
|---|
| 384 | + } |
|---|
| 385 | + } |
|---|
| 386 | + |
|---|
| 387 | + /* |
|---|
| 388 | + * Some Cherry Trail boards with an ES8316 codec have a bug in their |
|---|
| 389 | + * ACPI tables where the MSSL1680 touchscreen's _PS0 and _PS3 methods |
|---|
| 390 | + * wrongly also set the speaker-enable GPIO to 1/0. Testing has shown |
|---|
| 391 | + * that this really is a bug and the GPIO has no influence on the |
|---|
| 392 | + * touchscreen at all. |
|---|
| 393 | + * |
|---|
| 394 | + * The silead.c touchscreen driver does not support runtime suspend, so |
|---|
| 395 | + * the GPIO can only be changed underneath us during a system suspend. |
|---|
| 396 | + * This resume() function runs from a pm complete() callback, and thus |
|---|
| 397 | + * is guaranteed to run after the touchscreen driver/ACPI-subsys has |
|---|
| 398 | + * brought the touchscreen back up again (and thus changed the GPIO). |
|---|
| 399 | + * |
|---|
| 400 | + * So to work around this we pass GPIOD_FLAGS_BIT_NONEXCLUSIVE when |
|---|
| 401 | + * requesting the GPIO and we set its value here to undo any changes |
|---|
| 402 | + * done by the touchscreen's broken _PS0 ACPI method. |
|---|
| 403 | + */ |
|---|
| 404 | + gpiod_set_value_cansleep(priv->speaker_en_gpio, priv->speaker_en); |
|---|
| 405 | + |
|---|
| 406 | + return 0; |
|---|
| 407 | +} |
|---|
| 408 | + |
|---|
| 409 | +#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) |
|---|
| 410 | +/* use space before codec name to simplify card ID, and simplify driver name */ |
|---|
| 411 | +#define CARD_NAME "bytcht es8316" /* card name will be 'sof-bytcht es8316' */ |
|---|
| 412 | +#define DRIVER_NAME "SOF" |
|---|
| 413 | +#else |
|---|
| 414 | +#define CARD_NAME "bytcht-es8316" |
|---|
| 415 | +#define DRIVER_NAME NULL /* card name will be used for driver name */ |
|---|
| 416 | +#endif |
|---|
| 417 | + |
|---|
| 221 | 418 | static struct snd_soc_card byt_cht_es8316_card = { |
|---|
| 222 | | - .name = "bytcht-es8316", |
|---|
| 419 | + .name = CARD_NAME, |
|---|
| 420 | + .driver_name = DRIVER_NAME, |
|---|
| 223 | 421 | .owner = THIS_MODULE, |
|---|
| 224 | 422 | .dai_link = byt_cht_es8316_dais, |
|---|
| 225 | 423 | .num_links = ARRAY_SIZE(byt_cht_es8316_dais), |
|---|
| .. | .. |
|---|
| 230 | 428 | .controls = byt_cht_es8316_controls, |
|---|
| 231 | 429 | .num_controls = ARRAY_SIZE(byt_cht_es8316_controls), |
|---|
| 232 | 430 | .fully_routed = true, |
|---|
| 431 | + .suspend_pre = byt_cht_es8316_suspend, |
|---|
| 432 | + .resume_post = byt_cht_es8316_resume, |
|---|
| 233 | 433 | }; |
|---|
| 234 | 434 | |
|---|
| 235 | | -static char codec_name[SND_ACPI_I2C_ID_LEN]; |
|---|
| 435 | +static const struct acpi_gpio_params first_gpio = { 0, 0, false }; |
|---|
| 436 | + |
|---|
| 437 | +static const struct acpi_gpio_mapping byt_cht_es8316_gpios[] = { |
|---|
| 438 | + { "speaker-enable-gpios", &first_gpio, 1 }, |
|---|
| 439 | + { }, |
|---|
| 440 | +}; |
|---|
| 441 | + |
|---|
| 442 | +/* Please keep this list alphabetically sorted */ |
|---|
| 443 | +static const struct dmi_system_id byt_cht_es8316_quirk_table[] = { |
|---|
| 444 | + { /* Irbis NB41 */ |
|---|
| 445 | + .matches = { |
|---|
| 446 | + DMI_MATCH(DMI_SYS_VENDOR, "IRBIS"), |
|---|
| 447 | + DMI_MATCH(DMI_PRODUCT_NAME, "NB41"), |
|---|
| 448 | + }, |
|---|
| 449 | + .driver_data = (void *)(BYT_CHT_ES8316_SSP0 |
|---|
| 450 | + | BYT_CHT_ES8316_INTMIC_IN2_MAP |
|---|
| 451 | + | BYT_CHT_ES8316_JD_INVERTED), |
|---|
| 452 | + }, |
|---|
| 453 | + { /* Nanote UMPC-01 */ |
|---|
| 454 | + .matches = { |
|---|
| 455 | + DMI_MATCH(DMI_SYS_VENDOR, "RWC CO.,LTD"), |
|---|
| 456 | + DMI_MATCH(DMI_PRODUCT_NAME, "UMPC-01"), |
|---|
| 457 | + }, |
|---|
| 458 | + .driver_data = (void *)BYT_CHT_ES8316_INTMIC_IN1_MAP, |
|---|
| 459 | + }, |
|---|
| 460 | + { /* Teclast X98 Plus II */ |
|---|
| 461 | + .matches = { |
|---|
| 462 | + DMI_MATCH(DMI_SYS_VENDOR, "TECLAST"), |
|---|
| 463 | + DMI_MATCH(DMI_PRODUCT_NAME, "X98 Plus II"), |
|---|
| 464 | + }, |
|---|
| 465 | + .driver_data = (void *)(BYT_CHT_ES8316_INTMIC_IN1_MAP |
|---|
| 466 | + | BYT_CHT_ES8316_JD_INVERTED), |
|---|
| 467 | + }, |
|---|
| 468 | + {} |
|---|
| 469 | +}; |
|---|
| 236 | 470 | |
|---|
| 237 | 471 | static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev) |
|---|
| 238 | 472 | { |
|---|
| 473 | + static const char * const mic_name[] = { "in1", "in2" }; |
|---|
| 474 | + struct property_entry props[MAX_NO_PROPS] = {}; |
|---|
| 239 | 475 | struct byt_cht_es8316_private *priv; |
|---|
| 476 | + const struct dmi_system_id *dmi_id; |
|---|
| 477 | + struct device *dev = &pdev->dev; |
|---|
| 240 | 478 | struct snd_soc_acpi_mach *mach; |
|---|
| 241 | | - const char *i2c_name = NULL; |
|---|
| 479 | + const char *platform_name; |
|---|
| 480 | + struct acpi_device *adev; |
|---|
| 481 | + struct device *codec_dev; |
|---|
| 482 | + unsigned int cnt = 0; |
|---|
| 242 | 483 | int dai_index = 0; |
|---|
| 243 | 484 | int i; |
|---|
| 244 | 485 | int ret = 0; |
|---|
| 245 | 486 | |
|---|
| 246 | | - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
|---|
| 487 | + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
|---|
| 247 | 488 | if (!priv) |
|---|
| 248 | 489 | return -ENOMEM; |
|---|
| 249 | 490 | |
|---|
| 250 | | - mach = (&pdev->dev)->platform_data; |
|---|
| 491 | + mach = dev->platform_data; |
|---|
| 251 | 492 | /* fix index of codec dai */ |
|---|
| 252 | 493 | for (i = 0; i < ARRAY_SIZE(byt_cht_es8316_dais); i++) { |
|---|
| 253 | | - if (!strcmp(byt_cht_es8316_dais[i].codec_name, |
|---|
| 494 | + if (!strcmp(byt_cht_es8316_dais[i].codecs->name, |
|---|
| 254 | 495 | "i2c-ESSX8316:00")) { |
|---|
| 255 | 496 | dai_index = i; |
|---|
| 256 | 497 | break; |
|---|
| .. | .. |
|---|
| 258 | 499 | } |
|---|
| 259 | 500 | |
|---|
| 260 | 501 | /* fixup codec name based on HID */ |
|---|
| 261 | | - i2c_name = acpi_dev_get_first_match_name(mach->id, NULL, -1); |
|---|
| 262 | | - if (i2c_name) { |
|---|
| 502 | + adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1); |
|---|
| 503 | + if (adev) { |
|---|
| 263 | 504 | snprintf(codec_name, sizeof(codec_name), |
|---|
| 264 | | - "%s%s", "i2c-", i2c_name); |
|---|
| 265 | | - byt_cht_es8316_dais[dai_index].codec_name = codec_name; |
|---|
| 505 | + "i2c-%s", acpi_dev_name(adev)); |
|---|
| 506 | + put_device(&adev->dev); |
|---|
| 507 | + byt_cht_es8316_dais[dai_index].codecs->name = codec_name; |
|---|
| 266 | 508 | } |
|---|
| 267 | 509 | |
|---|
| 268 | | - /* register the soc card */ |
|---|
| 269 | | - byt_cht_es8316_card.dev = &pdev->dev; |
|---|
| 270 | | - snd_soc_card_set_drvdata(&byt_cht_es8316_card, priv); |
|---|
| 510 | + /* override plaform name, if required */ |
|---|
| 511 | + byt_cht_es8316_card.dev = dev; |
|---|
| 512 | + platform_name = mach->mach_params.platform; |
|---|
| 271 | 513 | |
|---|
| 272 | | - priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3"); |
|---|
| 514 | + ret = snd_soc_fixup_dai_links_platform_name(&byt_cht_es8316_card, |
|---|
| 515 | + platform_name); |
|---|
| 516 | + if (ret) |
|---|
| 517 | + return ret; |
|---|
| 518 | + |
|---|
| 519 | + /* Check for BYTCR or other platform and setup quirks */ |
|---|
| 520 | + dmi_id = dmi_first_match(byt_cht_es8316_quirk_table); |
|---|
| 521 | + if (dmi_id) { |
|---|
| 522 | + quirk = (unsigned long)dmi_id->driver_data; |
|---|
| 523 | + } else if (soc_intel_is_byt() && |
|---|
| 524 | + mach->mach_params.acpi_ipc_irq_index == 0) { |
|---|
| 525 | + /* On BYTCR default to SSP0, internal-mic-in2-map, mono-spk */ |
|---|
| 526 | + quirk = BYT_CHT_ES8316_SSP0 | BYT_CHT_ES8316_INTMIC_IN2_MAP | |
|---|
| 527 | + BYT_CHT_ES8316_MONO_SPEAKER; |
|---|
| 528 | + } else { |
|---|
| 529 | + /* Others default to internal-mic-in1-map, mono-speaker */ |
|---|
| 530 | + quirk = BYT_CHT_ES8316_INTMIC_IN1_MAP | |
|---|
| 531 | + BYT_CHT_ES8316_MONO_SPEAKER; |
|---|
| 532 | + } |
|---|
| 533 | + if (quirk_override != -1) { |
|---|
| 534 | + dev_info(dev, "Overriding quirk 0x%lx => 0x%x\n", |
|---|
| 535 | + quirk, quirk_override); |
|---|
| 536 | + quirk = quirk_override; |
|---|
| 537 | + } |
|---|
| 538 | + log_quirks(dev); |
|---|
| 539 | + |
|---|
| 540 | + if (quirk & BYT_CHT_ES8316_SSP0) |
|---|
| 541 | + byt_cht_es8316_dais[dai_index].cpus->dai_name = "ssp0-port"; |
|---|
| 542 | + |
|---|
| 543 | + /* get the clock */ |
|---|
| 544 | + priv->mclk = devm_clk_get(dev, "pmc_plt_clk_3"); |
|---|
| 273 | 545 | if (IS_ERR(priv->mclk)) { |
|---|
| 274 | 546 | ret = PTR_ERR(priv->mclk); |
|---|
| 275 | | - dev_err(&pdev->dev, |
|---|
| 276 | | - "Failed to get MCLK from pmc_plt_clk_3: %d\n", |
|---|
| 277 | | - ret); |
|---|
| 547 | + dev_err(dev, "clk_get pmc_plt_clk_3 failed: %d\n", ret); |
|---|
| 278 | 548 | return ret; |
|---|
| 279 | 549 | } |
|---|
| 280 | 550 | |
|---|
| 281 | | - ret = devm_snd_soc_register_card(&pdev->dev, &byt_cht_es8316_card); |
|---|
| 551 | + /* get speaker enable GPIO */ |
|---|
| 552 | + codec_dev = bus_find_device_by_name(&i2c_bus_type, NULL, codec_name); |
|---|
| 553 | + if (!codec_dev) |
|---|
| 554 | + return -EPROBE_DEFER; |
|---|
| 555 | + |
|---|
| 556 | + if (quirk & BYT_CHT_ES8316_JD_INVERTED) |
|---|
| 557 | + props[cnt++] = PROPERTY_ENTRY_BOOL("everest,jack-detect-inverted"); |
|---|
| 558 | + |
|---|
| 559 | + if (cnt) { |
|---|
| 560 | + ret = device_add_properties(codec_dev, props); |
|---|
| 561 | + if (ret) { |
|---|
| 562 | + put_device(codec_dev); |
|---|
| 563 | + return ret; |
|---|
| 564 | + } |
|---|
| 565 | + } |
|---|
| 566 | + |
|---|
| 567 | + devm_acpi_dev_add_driver_gpios(codec_dev, byt_cht_es8316_gpios); |
|---|
| 568 | + priv->speaker_en_gpio = |
|---|
| 569 | + gpiod_get_index(codec_dev, "speaker-enable", 0, |
|---|
| 570 | + /* see comment in byt_cht_es8316_resume */ |
|---|
| 571 | + GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE); |
|---|
| 572 | + put_device(codec_dev); |
|---|
| 573 | + |
|---|
| 574 | + if (IS_ERR(priv->speaker_en_gpio)) { |
|---|
| 575 | + ret = PTR_ERR(priv->speaker_en_gpio); |
|---|
| 576 | + switch (ret) { |
|---|
| 577 | + case -ENOENT: |
|---|
| 578 | + priv->speaker_en_gpio = NULL; |
|---|
| 579 | + break; |
|---|
| 580 | + default: |
|---|
| 581 | + dev_err(dev, "get speaker GPIO failed: %d\n", ret); |
|---|
| 582 | + fallthrough; |
|---|
| 583 | + case -EPROBE_DEFER: |
|---|
| 584 | + return ret; |
|---|
| 585 | + } |
|---|
| 586 | + } |
|---|
| 587 | + |
|---|
| 588 | + snprintf(components_string, sizeof(components_string), |
|---|
| 589 | + "cfg-spk:%s cfg-mic:%s", |
|---|
| 590 | + (quirk & BYT_CHT_ES8316_MONO_SPEAKER) ? "1" : "2", |
|---|
| 591 | + mic_name[BYT_CHT_ES8316_MAP(quirk)]); |
|---|
| 592 | + byt_cht_es8316_card.components = components_string; |
|---|
| 593 | +#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES) |
|---|
| 594 | + snprintf(long_name, sizeof(long_name), "bytcht-es8316-%s-spk-%s-mic", |
|---|
| 595 | + (quirk & BYT_CHT_ES8316_MONO_SPEAKER) ? "mono" : "stereo", |
|---|
| 596 | + mic_name[BYT_CHT_ES8316_MAP(quirk)]); |
|---|
| 597 | + byt_cht_es8316_card.long_name = long_name; |
|---|
| 598 | +#endif |
|---|
| 599 | + |
|---|
| 600 | + /* register the soc card */ |
|---|
| 601 | + snd_soc_card_set_drvdata(&byt_cht_es8316_card, priv); |
|---|
| 602 | + |
|---|
| 603 | + ret = devm_snd_soc_register_card(dev, &byt_cht_es8316_card); |
|---|
| 282 | 604 | if (ret) { |
|---|
| 283 | | - dev_err(&pdev->dev, "snd_soc_register_card failed %d\n", ret); |
|---|
| 605 | + gpiod_put(priv->speaker_en_gpio); |
|---|
| 606 | + dev_err(dev, "snd_soc_register_card failed: %d\n", ret); |
|---|
| 284 | 607 | return ret; |
|---|
| 285 | 608 | } |
|---|
| 286 | 609 | platform_set_drvdata(pdev, &byt_cht_es8316_card); |
|---|
| 287 | | - return ret; |
|---|
| 610 | + return 0; |
|---|
| 611 | +} |
|---|
| 612 | + |
|---|
| 613 | +static int snd_byt_cht_es8316_mc_remove(struct platform_device *pdev) |
|---|
| 614 | +{ |
|---|
| 615 | + struct snd_soc_card *card = platform_get_drvdata(pdev); |
|---|
| 616 | + struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card); |
|---|
| 617 | + |
|---|
| 618 | + gpiod_put(priv->speaker_en_gpio); |
|---|
| 619 | + return 0; |
|---|
| 288 | 620 | } |
|---|
| 289 | 621 | |
|---|
| 290 | 622 | static struct platform_driver snd_byt_cht_es8316_mc_driver = { |
|---|
| 291 | 623 | .driver = { |
|---|
| 292 | 624 | .name = "bytcht_es8316", |
|---|
| 625 | +#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) |
|---|
| 626 | + .pm = &snd_soc_pm_ops, |
|---|
| 627 | +#endif |
|---|
| 293 | 628 | }, |
|---|
| 294 | 629 | .probe = snd_byt_cht_es8316_mc_probe, |
|---|
| 630 | + .remove = snd_byt_cht_es8316_mc_remove, |
|---|
| 295 | 631 | }; |
|---|
| 296 | 632 | |
|---|
| 297 | 633 | module_platform_driver(snd_byt_cht_es8316_mc_driver); |
|---|