0001
0002
0003
0004 #include <linux/module.h>
0005 #include <linux/string.h>
0006 #include <sound/pcm.h>
0007 #include <sound/soc.h>
0008 #include <sound/soc-acpi.h>
0009 #include <sound/soc-dai.h>
0010 #include <sound/soc-dapm.h>
0011 #include <uapi/sound/asound.h>
0012 #include "sof_maxim_common.h"
0013
0014 #define MAX_98373_PIN_NAME 16
0015
0016 const struct snd_soc_dapm_route max_98373_dapm_routes[] = {
0017
0018 { "Left Spk", NULL, "Left BE_OUT" },
0019 { "Right Spk", NULL, "Right BE_OUT" },
0020 };
0021 EXPORT_SYMBOL_NS(max_98373_dapm_routes, SND_SOC_INTEL_SOF_MAXIM_COMMON);
0022
0023 static struct snd_soc_codec_conf max_98373_codec_conf[] = {
0024 {
0025 .dlc = COMP_CODEC_CONF(MAX_98373_DEV0_NAME),
0026 .name_prefix = "Right",
0027 },
0028 {
0029 .dlc = COMP_CODEC_CONF(MAX_98373_DEV1_NAME),
0030 .name_prefix = "Left",
0031 },
0032 };
0033
0034 struct snd_soc_dai_link_component max_98373_components[] = {
0035 {
0036 .name = MAX_98373_DEV0_NAME,
0037 .dai_name = MAX_98373_CODEC_DAI,
0038 },
0039 {
0040 .name = MAX_98373_DEV1_NAME,
0041 .dai_name = MAX_98373_CODEC_DAI,
0042 },
0043 };
0044 EXPORT_SYMBOL_NS(max_98373_components, SND_SOC_INTEL_SOF_MAXIM_COMMON);
0045
0046 static int max_98373_hw_params(struct snd_pcm_substream *substream,
0047 struct snd_pcm_hw_params *params)
0048 {
0049 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0050 struct snd_soc_dai *codec_dai;
0051 int j;
0052
0053 for_each_rtd_codec_dais(rtd, j, codec_dai) {
0054 if (!strcmp(codec_dai->component->name, MAX_98373_DEV0_NAME)) {
0055
0056 snd_soc_dai_set_tdm_slot(codec_dai, 0x03, 3, 8, 32);
0057 }
0058 if (!strcmp(codec_dai->component->name, MAX_98373_DEV1_NAME)) {
0059
0060 snd_soc_dai_set_tdm_slot(codec_dai, 0x0C, 3, 8, 32);
0061 }
0062 }
0063 return 0;
0064 }
0065
0066 int max_98373_trigger(struct snd_pcm_substream *substream, int cmd)
0067 {
0068 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0069 struct snd_soc_dai *codec_dai;
0070 struct snd_soc_dai *cpu_dai;
0071 int j;
0072 int ret = 0;
0073
0074
0075 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
0076 return 0;
0077
0078 cpu_dai = asoc_rtd_to_cpu(rtd, 0);
0079 for_each_rtd_codec_dais(rtd, j, codec_dai) {
0080 struct snd_soc_dapm_context *dapm =
0081 snd_soc_component_get_dapm(cpu_dai->component);
0082 char pin_name[MAX_98373_PIN_NAME];
0083
0084 snprintf(pin_name, ARRAY_SIZE(pin_name), "%s Spk",
0085 codec_dai->component->name_prefix);
0086
0087 switch (cmd) {
0088 case SNDRV_PCM_TRIGGER_START:
0089 case SNDRV_PCM_TRIGGER_RESUME:
0090 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
0091 ret = snd_soc_dapm_enable_pin(dapm, pin_name);
0092 if (!ret)
0093 snd_soc_dapm_sync(dapm);
0094 break;
0095 case SNDRV_PCM_TRIGGER_STOP:
0096 case SNDRV_PCM_TRIGGER_SUSPEND:
0097 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
0098 ret = snd_soc_dapm_disable_pin(dapm, pin_name);
0099 if (!ret)
0100 snd_soc_dapm_sync(dapm);
0101 break;
0102 default:
0103 break;
0104 }
0105 }
0106
0107 return ret;
0108 }
0109 EXPORT_SYMBOL_NS(max_98373_trigger, SND_SOC_INTEL_SOF_MAXIM_COMMON);
0110
0111 struct snd_soc_ops max_98373_ops = {
0112 .hw_params = max_98373_hw_params,
0113 .trigger = max_98373_trigger,
0114 };
0115 EXPORT_SYMBOL_NS(max_98373_ops, SND_SOC_INTEL_SOF_MAXIM_COMMON);
0116
0117 int max_98373_spk_codec_init(struct snd_soc_pcm_runtime *rtd)
0118 {
0119 struct snd_soc_card *card = rtd->card;
0120 int ret;
0121
0122 ret = snd_soc_dapm_add_routes(&card->dapm, max_98373_dapm_routes,
0123 ARRAY_SIZE(max_98373_dapm_routes));
0124 if (ret)
0125 dev_err(rtd->dev, "Speaker map addition failed: %d\n", ret);
0126 return ret;
0127 }
0128 EXPORT_SYMBOL_NS(max_98373_spk_codec_init, SND_SOC_INTEL_SOF_MAXIM_COMMON);
0129
0130 void max_98373_set_codec_conf(struct snd_soc_card *card)
0131 {
0132 card->codec_conf = max_98373_codec_conf;
0133 card->num_configs = ARRAY_SIZE(max_98373_codec_conf);
0134 }
0135 EXPORT_SYMBOL_NS(max_98373_set_codec_conf, SND_SOC_INTEL_SOF_MAXIM_COMMON);
0136
0137
0138
0139
0140 static const struct snd_soc_dapm_route max_98390_dapm_routes[] = {
0141
0142 { "Left Spk", NULL, "Left BE_OUT" },
0143 { "Right Spk", NULL, "Right BE_OUT" },
0144 };
0145
0146 static const struct snd_kcontrol_new max_98390_tt_kcontrols[] = {
0147 SOC_DAPM_PIN_SWITCH("TL Spk"),
0148 SOC_DAPM_PIN_SWITCH("TR Spk"),
0149 };
0150
0151 static const struct snd_soc_dapm_widget max_98390_tt_dapm_widgets[] = {
0152 SND_SOC_DAPM_SPK("TL Spk", NULL),
0153 SND_SOC_DAPM_SPK("TR Spk", NULL),
0154 };
0155
0156 static const struct snd_soc_dapm_route max_98390_tt_dapm_routes[] = {
0157
0158 { "TL Spk", NULL, "Tweeter Left BE_OUT" },
0159 { "TR Spk", NULL, "Tweeter Right BE_OUT" },
0160 };
0161
0162 static struct snd_soc_codec_conf max_98390_codec_conf[] = {
0163 {
0164 .dlc = COMP_CODEC_CONF(MAX_98390_DEV0_NAME),
0165 .name_prefix = "Right",
0166 },
0167 {
0168 .dlc = COMP_CODEC_CONF(MAX_98390_DEV1_NAME),
0169 .name_prefix = "Left",
0170 },
0171 };
0172
0173 static struct snd_soc_codec_conf max_98390_4spk_codec_conf[] = {
0174 {
0175 .dlc = COMP_CODEC_CONF(MAX_98390_DEV0_NAME),
0176 .name_prefix = "Right",
0177 },
0178 {
0179 .dlc = COMP_CODEC_CONF(MAX_98390_DEV1_NAME),
0180 .name_prefix = "Left",
0181 },
0182 {
0183 .dlc = COMP_CODEC_CONF(MAX_98390_DEV2_NAME),
0184 .name_prefix = "Tweeter Right",
0185 },
0186 {
0187 .dlc = COMP_CODEC_CONF(MAX_98390_DEV3_NAME),
0188 .name_prefix = "Tweeter Left",
0189 },
0190 };
0191
0192 struct snd_soc_dai_link_component max_98390_components[] = {
0193 {
0194 .name = MAX_98390_DEV0_NAME,
0195 .dai_name = MAX_98390_CODEC_DAI,
0196 },
0197 {
0198 .name = MAX_98390_DEV1_NAME,
0199 .dai_name = MAX_98390_CODEC_DAI,
0200 },
0201 };
0202 EXPORT_SYMBOL_NS(max_98390_components, SND_SOC_INTEL_SOF_MAXIM_COMMON);
0203
0204 struct snd_soc_dai_link_component max_98390_4spk_components[] = {
0205 {
0206 .name = MAX_98390_DEV0_NAME,
0207 .dai_name = MAX_98390_CODEC_DAI,
0208 },
0209 {
0210 .name = MAX_98390_DEV1_NAME,
0211 .dai_name = MAX_98390_CODEC_DAI,
0212 },
0213 {
0214 .name = MAX_98390_DEV2_NAME,
0215 .dai_name = MAX_98390_CODEC_DAI,
0216 },
0217 {
0218 .name = MAX_98390_DEV3_NAME,
0219 .dai_name = MAX_98390_CODEC_DAI,
0220 },
0221 };
0222 EXPORT_SYMBOL_NS(max_98390_4spk_components, SND_SOC_INTEL_SOF_MAXIM_COMMON);
0223
0224 static int max_98390_hw_params(struct snd_pcm_substream *substream,
0225 struct snd_pcm_hw_params *params)
0226 {
0227 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0228 struct snd_soc_dai *codec_dai;
0229 int i;
0230
0231 for_each_rtd_codec_dais(rtd, i, codec_dai) {
0232 if (i >= ARRAY_SIZE(max_98390_4spk_components)) {
0233 dev_err(codec_dai->dev, "invalid codec index %d\n", i);
0234 return -ENODEV;
0235 }
0236
0237 if (!strcmp(codec_dai->component->name, MAX_98390_DEV0_NAME)) {
0238
0239 snd_soc_dai_set_tdm_slot(codec_dai, 0x01, 3, 4, 32);
0240 }
0241 if (!strcmp(codec_dai->component->name, MAX_98390_DEV1_NAME)) {
0242
0243 snd_soc_dai_set_tdm_slot(codec_dai, 0x02, 3, 4, 32);
0244 }
0245
0246 if (!strcmp(codec_dai->component->name, MAX_98390_DEV2_NAME)) {
0247
0248 snd_soc_dai_set_tdm_slot(codec_dai, 0x04, 3, 4, 32);
0249 }
0250 if (!strcmp(codec_dai->component->name, MAX_98390_DEV3_NAME)) {
0251
0252 snd_soc_dai_set_tdm_slot(codec_dai, 0x08, 3, 4, 32);
0253 }
0254 }
0255 return 0;
0256 }
0257
0258 int max_98390_spk_codec_init(struct snd_soc_pcm_runtime *rtd)
0259 {
0260 struct snd_soc_card *card = rtd->card;
0261 int ret;
0262
0263
0264 ret = snd_soc_dapm_add_routes(&card->dapm, max_98390_dapm_routes,
0265 ARRAY_SIZE(max_98390_dapm_routes));
0266 if (ret) {
0267 dev_err(rtd->dev, "unable to add Left/Right Speaker dapm, ret %d\n", ret);
0268 return ret;
0269 }
0270
0271
0272 if (acpi_dev_present("MX98390", "3", -1)) {
0273 ret = snd_soc_dapm_new_controls(&card->dapm, max_98390_tt_dapm_widgets,
0274 ARRAY_SIZE(max_98390_tt_dapm_widgets));
0275
0276 if (ret) {
0277 dev_err(rtd->dev, "unable to add tweeter dapm controls, ret %d\n", ret);
0278
0279 return ret;
0280 }
0281
0282 ret = snd_soc_add_card_controls(card, max_98390_tt_kcontrols,
0283 ARRAY_SIZE(max_98390_tt_kcontrols));
0284 if (ret) {
0285 dev_err(rtd->dev, "unable to add tweeter card controls, ret %d\n", ret);
0286 return ret;
0287 }
0288
0289 ret = snd_soc_dapm_add_routes(&card->dapm, max_98390_tt_dapm_routes,
0290 ARRAY_SIZE(max_98390_tt_dapm_routes));
0291 if (ret)
0292 dev_err(rtd->dev,
0293 "unable to add Tweeter Left/Right Speaker dapm, ret %d\n", ret);
0294 }
0295 return ret;
0296 }
0297 EXPORT_SYMBOL_NS(max_98390_spk_codec_init, SND_SOC_INTEL_SOF_MAXIM_COMMON);
0298
0299 const struct snd_soc_ops max_98390_ops = {
0300 .hw_params = max_98390_hw_params,
0301 };
0302 EXPORT_SYMBOL_NS(max_98390_ops, SND_SOC_INTEL_SOF_MAXIM_COMMON);
0303
0304 void max_98390_set_codec_conf(struct snd_soc_card *card, int ch)
0305 {
0306 if (ch == ARRAY_SIZE(max_98390_4spk_codec_conf)) {
0307 card->codec_conf = max_98390_4spk_codec_conf;
0308 card->num_configs = ARRAY_SIZE(max_98390_4spk_codec_conf);
0309 } else {
0310 card->codec_conf = max_98390_codec_conf;
0311 card->num_configs = ARRAY_SIZE(max_98390_codec_conf);
0312 }
0313 }
0314 EXPORT_SYMBOL_NS(max_98390_set_codec_conf, SND_SOC_INTEL_SOF_MAXIM_COMMON);
0315
0316
0317
0318
0319 static const struct snd_kcontrol_new max_98357a_kcontrols[] = {
0320 SOC_DAPM_PIN_SWITCH("Spk"),
0321 };
0322
0323 static const struct snd_soc_dapm_widget max_98357a_dapm_widgets[] = {
0324 SND_SOC_DAPM_SPK("Spk", NULL),
0325 };
0326
0327 static const struct snd_soc_dapm_route max_98357a_dapm_routes[] = {
0328
0329 {"Spk", NULL, "Speaker"},
0330 };
0331
0332 static struct snd_soc_dai_link_component max_98357a_components[] = {
0333 {
0334 .name = MAX_98357A_DEV0_NAME,
0335 .dai_name = MAX_98357A_CODEC_DAI,
0336 }
0337 };
0338
0339 static struct snd_soc_dai_link_component max_98360a_components[] = {
0340 {
0341 .name = MAX_98360A_DEV0_NAME,
0342 .dai_name = MAX_98357A_CODEC_DAI,
0343 }
0344 };
0345
0346 static int max_98357a_init(struct snd_soc_pcm_runtime *rtd)
0347 {
0348 struct snd_soc_card *card = rtd->card;
0349 int ret;
0350
0351 ret = snd_soc_dapm_new_controls(&card->dapm, max_98357a_dapm_widgets,
0352 ARRAY_SIZE(max_98357a_dapm_widgets));
0353 if (ret) {
0354 dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret);
0355
0356 return ret;
0357 }
0358
0359 ret = snd_soc_add_card_controls(card, max_98357a_kcontrols,
0360 ARRAY_SIZE(max_98357a_kcontrols));
0361 if (ret) {
0362 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
0363 return ret;
0364 }
0365
0366 ret = snd_soc_dapm_add_routes(&card->dapm, max_98357a_dapm_routes,
0367 ARRAY_SIZE(max_98357a_dapm_routes));
0368
0369 if (ret)
0370 dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret);
0371
0372 return ret;
0373 }
0374
0375 void max_98357a_dai_link(struct snd_soc_dai_link *link)
0376 {
0377 link->codecs = max_98357a_components;
0378 link->num_codecs = ARRAY_SIZE(max_98357a_components);
0379 link->init = max_98357a_init;
0380 }
0381 EXPORT_SYMBOL_NS(max_98357a_dai_link, SND_SOC_INTEL_SOF_MAXIM_COMMON);
0382
0383 void max_98360a_dai_link(struct snd_soc_dai_link *link)
0384 {
0385 link->codecs = max_98360a_components;
0386 link->num_codecs = ARRAY_SIZE(max_98360a_components);
0387 link->init = max_98357a_init;
0388 }
0389 EXPORT_SYMBOL_NS(max_98360a_dai_link, SND_SOC_INTEL_SOF_MAXIM_COMMON);
0390
0391 MODULE_DESCRIPTION("ASoC Intel SOF Maxim helpers");
0392 MODULE_LICENSE("GPL");