1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * bytcht_nocodec.c - ASoc Machine driver for MinnowBoard Max and Up 4 * to make I2S signals observable on the Low-Speed connector. Audio codec 5 * is not managed by ASoC/DAPM 6 * 7 * Copyright (C) 2015-2017 Intel Corp 8 * 9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10 * 11 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12 */ 13 14 #include <linux/module.h> 15 #include <sound/pcm.h> 16 #include <sound/pcm_params.h> 17 #include <sound/soc.h> 18 #include "../atom/sst-atom-controls.h" 19 20 static const struct snd_soc_dapm_widget widgets[] = { 21 SND_SOC_DAPM_MIC("Mic", NULL), 22 SND_SOC_DAPM_SPK("Speaker", NULL), 23 }; 24 25 static const struct snd_kcontrol_new controls[] = { 26 SOC_DAPM_PIN_SWITCH("Mic"), 27 SOC_DAPM_PIN_SWITCH("Speaker"), 28 }; 29 30 static const struct snd_soc_dapm_route audio_map[] = { 31 {"ssp2 Tx", NULL, "codec_out0"}, 32 {"ssp2 Tx", NULL, "codec_out1"}, 33 {"codec_in0", NULL, "ssp2 Rx"}, 34 {"codec_in1", NULL, "ssp2 Rx"}, 35 36 {"ssp2 Rx", NULL, "Mic"}, 37 {"Speaker", NULL, "ssp2 Tx"}, 38 }; 39 40 static int codec_fixup(struct snd_soc_pcm_runtime *rtd, 41 struct snd_pcm_hw_params *params) 42 { 43 struct snd_interval *rate = hw_param_interval(params, 44 SNDRV_PCM_HW_PARAM_RATE); 45 struct snd_interval *channels = hw_param_interval(params, 46 SNDRV_PCM_HW_PARAM_CHANNELS); 47 int ret; 48 49 /* The DSP will convert the FE rate to 48k, stereo, 24bits */ 50 rate->min = rate->max = 48000; 51 channels->min = channels->max = 2; 52 53 /* set SSP2 to 24-bit */ 54 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); 55 56 /* 57 * Default mode for SSP configuration is TDM 4 slot, override config 58 * with explicit setting to I2S 2ch 24-bit. The word length is set with 59 * dai_set_tdm_slot() since there is no other API exposed 60 */ 61 ret = snd_soc_dai_set_fmt(rtd->cpu_dai, 62 SND_SOC_DAIFMT_I2S | 63 SND_SOC_DAIFMT_NB_NF | 64 SND_SOC_DAIFMT_CBS_CFS); 65 66 if (ret < 0) { 67 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret); 68 return ret; 69 } 70 71 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24); 72 if (ret < 0) { 73 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret); 74 return ret; 75 } 76 77 return 0; 78 } 79 80 static const unsigned int rates_48000[] = { 81 48000, 82 }; 83 84 static const struct snd_pcm_hw_constraint_list constraints_48000 = { 85 .count = ARRAY_SIZE(rates_48000), 86 .list = rates_48000, 87 }; 88 89 static int aif1_startup(struct snd_pcm_substream *substream) 90 { 91 return snd_pcm_hw_constraint_list(substream->runtime, 0, 92 SNDRV_PCM_HW_PARAM_RATE, 93 &constraints_48000); 94 } 95 96 static struct snd_soc_ops aif1_ops = { 97 .startup = aif1_startup, 98 }; 99 100 static struct snd_soc_dai_link dais[] = { 101 [MERR_DPCM_AUDIO] = { 102 .name = "Audio Port", 103 .stream_name = "Audio", 104 .cpu_dai_name = "media-cpu-dai", 105 .codec_dai_name = "snd-soc-dummy-dai", 106 .codec_name = "snd-soc-dummy", 107 .platform_name = "sst-mfld-platform", 108 .ignore_suspend = 1, 109 .nonatomic = true, 110 .dynamic = 1, 111 .dpcm_playback = 1, 112 .dpcm_capture = 1, 113 .ops = &aif1_ops, 114 }, 115 [MERR_DPCM_DEEP_BUFFER] = { 116 .name = "Deep-Buffer Audio Port", 117 .stream_name = "Deep-Buffer Audio", 118 .cpu_dai_name = "deepbuffer-cpu-dai", 119 .codec_dai_name = "snd-soc-dummy-dai", 120 .codec_name = "snd-soc-dummy", 121 .platform_name = "sst-mfld-platform", 122 .ignore_suspend = 1, 123 .nonatomic = true, 124 .dynamic = 1, 125 .dpcm_playback = 1, 126 .ops = &aif1_ops, 127 }, 128 /* CODEC<->CODEC link */ 129 /* back ends */ 130 { 131 .name = "SSP2-LowSpeed Connector", 132 .id = 0, 133 .cpu_dai_name = "ssp2-port", 134 .platform_name = "sst-mfld-platform", 135 .no_pcm = 1, 136 .codec_dai_name = "snd-soc-dummy-dai", 137 .codec_name = "snd-soc-dummy", 138 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 139 | SND_SOC_DAIFMT_CBS_CFS, 140 .be_hw_params_fixup = codec_fixup, 141 .ignore_suspend = 1, 142 .nonatomic = true, 143 .dpcm_playback = 1, 144 .dpcm_capture = 1, 145 }, 146 }; 147 148 /* SoC card */ 149 static struct snd_soc_card bytcht_nocodec_card = { 150 .name = "bytcht-nocodec", 151 .owner = THIS_MODULE, 152 .dai_link = dais, 153 .num_links = ARRAY_SIZE(dais), 154 .dapm_widgets = widgets, 155 .num_dapm_widgets = ARRAY_SIZE(widgets), 156 .dapm_routes = audio_map, 157 .num_dapm_routes = ARRAY_SIZE(audio_map), 158 .controls = controls, 159 .num_controls = ARRAY_SIZE(controls), 160 .fully_routed = true, 161 }; 162 163 static int snd_bytcht_nocodec_mc_probe(struct platform_device *pdev) 164 { 165 int ret_val = 0; 166 167 /* register the soc card */ 168 bytcht_nocodec_card.dev = &pdev->dev; 169 170 ret_val = devm_snd_soc_register_card(&pdev->dev, &bytcht_nocodec_card); 171 172 if (ret_val) { 173 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n", 174 ret_val); 175 return ret_val; 176 } 177 platform_set_drvdata(pdev, &bytcht_nocodec_card); 178 return ret_val; 179 } 180 181 static struct platform_driver snd_bytcht_nocodec_mc_driver = { 182 .driver = { 183 .name = "bytcht_nocodec", 184 }, 185 .probe = snd_bytcht_nocodec_mc_probe, 186 }; 187 module_platform_driver(snd_bytcht_nocodec_mc_driver); 188 189 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail/Cherrytrail Nocodec Machine driver"); 190 MODULE_AUTHOR("Pierre-Louis Bossart <pierre-louis.bossart at linux.intel.com>"); 191 MODULE_LICENSE("GPL v2"); 192 MODULE_ALIAS("platform:bytcht_nocodec"); 193