Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2// Copyright(c) 2018-2020 Intel Corporation.
  3
  4/*
  5 * Intel SOF Machine Driver for Intel platforms with TI PCM512x codec,
  6 * e.g. Up or Up2 with Hifiberry DAC+ HAT
  7 */
  8#include <linux/clk.h>
  9#include <linux/dmi.h>
 10#include <linux/i2c.h>
 11#include <linux/input.h>
 12#include <linux/module.h>
 13#include <linux/platform_device.h>
 14#include <linux/types.h>
 15#include <sound/core.h>
 16#include <sound/jack.h>
 17#include <sound/pcm.h>
 18#include <sound/pcm_params.h>
 19#include <sound/soc.h>
 20#include <sound/soc-acpi.h>
 21#include "../../codecs/pcm512x.h"
 22#include "../common/soc-intel-quirks.h"
 23#include "hda_dsp_common.h"
 24
 25#define NAME_SIZE 32
 26
 27#define SOF_PCM512X_SSP_CODEC(quirk)		((quirk) & GENMASK(3, 0))
 28#define SOF_PCM512X_SSP_CODEC_MASK			(GENMASK(3, 0))
 29#define SOF_PCM512X_ENABLE_SSP_CAPTURE		BIT(4)
 30#define SOF_PCM512X_ENABLE_DMIC			BIT(5)
 31
 32#define IDISP_CODEC_MASK	0x4
 33
 34/* Default: SSP5 */
 35static unsigned long sof_pcm512x_quirk =
 36	SOF_PCM512X_SSP_CODEC(5) |
 37	SOF_PCM512X_ENABLE_SSP_CAPTURE |
 38	SOF_PCM512X_ENABLE_DMIC;
 39
 40static bool is_legacy_cpu;
 41
 42struct sof_hdmi_pcm {
 43	struct list_head head;
 44	struct snd_soc_dai *codec_dai;
 45	int device;
 46};
 47
 48struct sof_card_private {
 49	struct list_head hdmi_pcm_list;
 50	bool idisp_codec;
 51};
 52
 53static int sof_pcm512x_quirk_cb(const struct dmi_system_id *id)
 54{
 55	sof_pcm512x_quirk = (unsigned long)id->driver_data;
 56	return 1;
 57}
 58
 59static const struct dmi_system_id sof_pcm512x_quirk_table[] = {
 60	{
 61		.callback = sof_pcm512x_quirk_cb,
 62		.matches = {
 63			DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
 64			DMI_MATCH(DMI_PRODUCT_NAME, "UP-CHT01"),
 65		},
 66		.driver_data = (void *)(SOF_PCM512X_SSP_CODEC(2)),
 67	},
 68	{}
 69};
 70
 71static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd)
 72{
 73	struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
 74	struct snd_soc_dai *dai = snd_soc_rtd_to_codec(rtd, 0);
 75	struct sof_hdmi_pcm *pcm;
 76
 77	pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
 78	if (!pcm)
 79		return -ENOMEM;
 80
 81	/* dai_link id is 1:1 mapped to the PCM device */
 82	pcm->device = rtd->dai_link->id;
 83	pcm->codec_dai = dai;
 84
 85	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
 86
 87	return 0;
 88}
 89
 90static int sof_pcm512x_codec_init(struct snd_soc_pcm_runtime *rtd)
 91{
 92	struct snd_soc_component *codec = snd_soc_rtd_to_codec(rtd, 0)->component;
 93
 94	snd_soc_component_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
 95	snd_soc_component_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
 96	snd_soc_component_update_bits(codec, PCM512x_GPIO_CONTROL_1,
 97				      0x08, 0x08);
 98
 99	return 0;
100}
101
102static int aif1_startup(struct snd_pcm_substream *substream)
103{
104	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
105	struct snd_soc_component *codec = snd_soc_rtd_to_codec(rtd, 0)->component;
106
107	snd_soc_component_update_bits(codec, PCM512x_GPIO_CONTROL_1,
108				      0x08, 0x08);
109
110	return 0;
111}
112
113static void aif1_shutdown(struct snd_pcm_substream *substream)
114{
115	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
116	struct snd_soc_component *codec = snd_soc_rtd_to_codec(rtd, 0)->component;
117
118	snd_soc_component_update_bits(codec, PCM512x_GPIO_CONTROL_1,
119				      0x08, 0x00);
120}
121
122static const struct snd_soc_ops sof_pcm512x_ops = {
123	.startup = aif1_startup,
124	.shutdown = aif1_shutdown,
125};
126
127static struct snd_soc_dai_link_component platform_component[] = {
128	{
129		/* name might be overridden during probe */
130		.name = "0000:00:1f.3"
131	}
132};
133
134static int sof_card_late_probe(struct snd_soc_card *card)
135{
136	struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
137	struct sof_hdmi_pcm *pcm;
138
139	/* HDMI is not supported by SOF on Baytrail/CherryTrail */
140	if (is_legacy_cpu)
141		return 0;
142
143	if (list_empty(&ctx->hdmi_pcm_list))
144		return -EINVAL;
145
146	if (!ctx->idisp_codec)
147		return 0;
148
149	pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm, head);
150
151	return hda_dsp_hdmi_build_controls(card, pcm->codec_dai->component);
152}
153
154static const struct snd_kcontrol_new sof_controls[] = {
155	SOC_DAPM_PIN_SWITCH("Ext Spk"),
156};
157
158static const struct snd_soc_dapm_widget sof_widgets[] = {
159	SND_SOC_DAPM_SPK("Ext Spk", NULL),
160};
161
162static const struct snd_soc_dapm_widget dmic_widgets[] = {
163	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
164};
165
166static const struct snd_soc_dapm_route sof_map[] = {
167	/* Speaker */
168	{"Ext Spk", NULL, "OUTR"},
169	{"Ext Spk", NULL, "OUTL"},
170};
171
172static const struct snd_soc_dapm_route dmic_map[] = {
173	/* digital mics */
174	{"DMic", NULL, "SoC DMIC"},
175};
176
177static int dmic_init(struct snd_soc_pcm_runtime *rtd)
178{
179	struct snd_soc_card *card = rtd->card;
180	int ret;
181
182	ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
183					ARRAY_SIZE(dmic_widgets));
184	if (ret) {
185		dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
186		/* Don't need to add routes if widget addition failed */
187		return ret;
188	}
189
190	ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
191				      ARRAY_SIZE(dmic_map));
192
193	if (ret)
194		dev_err(card->dev, "DMic map addition failed: %d\n", ret);
195
196	return ret;
197}
198
199/* sof audio machine driver for pcm512x codec */
200static struct snd_soc_card sof_audio_card_pcm512x = {
201	.name = "pcm512x",
202	.owner = THIS_MODULE,
203	.controls = sof_controls,
204	.num_controls = ARRAY_SIZE(sof_controls),
205	.dapm_widgets = sof_widgets,
206	.num_dapm_widgets = ARRAY_SIZE(sof_widgets),
207	.dapm_routes = sof_map,
208	.num_dapm_routes = ARRAY_SIZE(sof_map),
209	.fully_routed = true,
210	.late_probe = sof_card_late_probe,
211};
212
213SND_SOC_DAILINK_DEF(pcm512x_component,
214	DAILINK_COMP_ARRAY(COMP_CODEC("i2c-104C5122:00", "pcm512x-hifi")));
215SND_SOC_DAILINK_DEF(dmic_component,
216	DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
217
218static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
219							  int ssp_codec,
220							  int dmic_be_num,
221							  int hdmi_num,
222							  bool idisp_codec)
223{
224	struct snd_soc_dai_link_component *idisp_components;
225	struct snd_soc_dai_link_component *cpus;
226	struct snd_soc_dai_link *links;
227	int i, id = 0;
228
229	links = devm_kcalloc(dev, sof_audio_card_pcm512x.num_links,
230			sizeof(struct snd_soc_dai_link), GFP_KERNEL);
231	cpus = devm_kcalloc(dev, sof_audio_card_pcm512x.num_links,
232			sizeof(struct snd_soc_dai_link_component), GFP_KERNEL);
233	if (!links || !cpus)
234		goto devm_err;
235
236	/* codec SSP */
237	links[id].name = devm_kasprintf(dev, GFP_KERNEL,
238					"SSP%d-Codec", ssp_codec);
239	if (!links[id].name)
240		goto devm_err;
241
242	links[id].id = id;
243	links[id].codecs = pcm512x_component;
244	links[id].num_codecs = ARRAY_SIZE(pcm512x_component);
245	links[id].platforms = platform_component;
246	links[id].num_platforms = ARRAY_SIZE(platform_component);
247	links[id].init = sof_pcm512x_codec_init;
248	links[id].ops = &sof_pcm512x_ops;
 
 
249	/*
250	 * capture only supported with specific versions of the Hifiberry DAC+
 
251	 */
252	if (!(sof_pcm512x_quirk & SOF_PCM512X_ENABLE_SSP_CAPTURE))
253		links[id].playback_only = 1;
254	links[id].no_pcm = 1;
255	links[id].cpus = &cpus[id];
256	links[id].num_cpus = 1;
257	if (is_legacy_cpu) {
258		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
259							  "ssp%d-port",
260							  ssp_codec);
261		if (!links[id].cpus->dai_name)
262			goto devm_err;
263	} else {
264		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
265							  "SSP%d Pin",
266							  ssp_codec);
267		if (!links[id].cpus->dai_name)
268			goto devm_err;
269	}
270	id++;
271
272	/* dmic */
273	if (dmic_be_num > 0) {
274		/* at least we have dmic01 */
275		links[id].name = "dmic01";
276		links[id].cpus = &cpus[id];
277		links[id].cpus->dai_name = "DMIC01 Pin";
278		links[id].init = dmic_init;
279		if (dmic_be_num > 1) {
280			/* set up 2 BE links at most */
281			links[id + 1].name = "dmic16k";
282			links[id + 1].cpus = &cpus[id + 1];
283			links[id + 1].cpus->dai_name = "DMIC16k Pin";
284			dmic_be_num = 2;
285		}
286	}
287
288	for (i = 0; i < dmic_be_num; i++) {
289		links[id].id = id;
290		links[id].num_cpus = 1;
291		links[id].codecs = dmic_component;
292		links[id].num_codecs = ARRAY_SIZE(dmic_component);
293		links[id].platforms = platform_component;
294		links[id].num_platforms = ARRAY_SIZE(platform_component);
295		links[id].ignore_suspend = 1;
296		links[id].capture_only = 1;
297		links[id].no_pcm = 1;
298		id++;
299	}
300
301	/* HDMI */
302	if (hdmi_num > 0) {
303		idisp_components = devm_kcalloc(dev, hdmi_num,
304				sizeof(struct snd_soc_dai_link_component),
305				GFP_KERNEL);
306		if (!idisp_components)
307			goto devm_err;
308	}
309	for (i = 1; i <= hdmi_num; i++) {
310		links[id].name = devm_kasprintf(dev, GFP_KERNEL,
311						"iDisp%d", i);
312		if (!links[id].name)
313			goto devm_err;
314
315		links[id].id = id;
316		links[id].cpus = &cpus[id];
317		links[id].num_cpus = 1;
318		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
319							  "iDisp%d Pin", i);
320		if (!links[id].cpus->dai_name)
321			goto devm_err;
322
323		/*
324		 * topology cannot be loaded if codec is missing, so
325		 * use the dummy codec if needed
326		 */
327		if (idisp_codec) {
328			idisp_components[i - 1].name = "ehdaudio0D2";
329			idisp_components[i - 1].dai_name =
330				devm_kasprintf(dev, GFP_KERNEL,
331					       "intel-hdmi-hifi%d", i);
332		} else {
333			idisp_components[i - 1] = snd_soc_dummy_dlc;
 
334		}
335		if (!idisp_components[i - 1].dai_name)
336			goto devm_err;
337
338		links[id].codecs = &idisp_components[i - 1];
339		links[id].num_codecs = 1;
340		links[id].platforms = platform_component;
341		links[id].num_platforms = ARRAY_SIZE(platform_component);
342		links[id].init = sof_hdmi_init;
343		links[id].playback_only = 1;
344		links[id].no_pcm = 1;
345		id++;
346	}
347
348	return links;
349devm_err:
350	return NULL;
351}
352
353static int sof_audio_probe(struct platform_device *pdev)
354{
355	struct snd_soc_acpi_mach *mach = pdev->dev.platform_data;
356	struct snd_soc_dai_link *dai_links;
357	struct sof_card_private *ctx;
358	int dmic_be_num, hdmi_num;
359	int ret, ssp_codec;
360
361	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
362	if (!ctx)
363		return -ENOMEM;
364
365	hdmi_num = 0;
366	if (soc_intel_is_byt() || soc_intel_is_cht()) {
367		is_legacy_cpu = true;
368		dmic_be_num = 0;
369		/* default quirk for legacy cpu */
370		sof_pcm512x_quirk = SOF_PCM512X_SSP_CODEC(2);
371	} else {
372		dmic_be_num = 2;
373		if (mach->mach_params.codec_mask & IDISP_CODEC_MASK)
 
374			ctx->idisp_codec = true;
375
376		/* links are always present in topology */
377		hdmi_num = 3;
378	}
379
380	dmi_check_system(sof_pcm512x_quirk_table);
381
382	dev_dbg(&pdev->dev, "sof_pcm512x_quirk = %lx\n", sof_pcm512x_quirk);
383
384	ssp_codec = sof_pcm512x_quirk & SOF_PCM512X_SSP_CODEC_MASK;
385
386	if (!(sof_pcm512x_quirk & SOF_PCM512X_ENABLE_DMIC))
387		dmic_be_num = 0;
388
389	/* compute number of dai links */
390	sof_audio_card_pcm512x.num_links = 1 + dmic_be_num + hdmi_num;
391
392	dai_links = sof_card_dai_links_create(&pdev->dev, ssp_codec,
393					      dmic_be_num, hdmi_num,
394					      ctx->idisp_codec);
395	if (!dai_links)
396		return -ENOMEM;
397
398	sof_audio_card_pcm512x.dai_link = dai_links;
399
400	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
401
402	sof_audio_card_pcm512x.dev = &pdev->dev;
403
404	/* set platform name for each dailink */
405	ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_pcm512x,
406						    mach->mach_params.platform);
407	if (ret)
408		return ret;
409
410	snd_soc_card_set_drvdata(&sof_audio_card_pcm512x, ctx);
411
412	return devm_snd_soc_register_card(&pdev->dev,
413					  &sof_audio_card_pcm512x);
414}
415
416static void sof_pcm512x_remove(struct platform_device *pdev)
417{
418	struct snd_soc_card *card = platform_get_drvdata(pdev);
419	struct snd_soc_component *component;
420
421	for_each_card_components(card, component) {
422		if (!strcmp(component->name, pcm512x_component[0].name)) {
423			snd_soc_component_set_jack(component, NULL, NULL);
424			break;
425		}
426	}
 
 
427}
428
429static struct platform_driver sof_audio = {
430	.probe = sof_audio_probe,
431	.remove = sof_pcm512x_remove,
432	.driver = {
433		.name = "sof_pcm512x",
434		.pm = &snd_soc_pm_ops,
435	},
436};
437module_platform_driver(sof_audio)
438
439MODULE_DESCRIPTION("ASoC Intel(R) SOF + PCM512x Machine driver");
440MODULE_AUTHOR("Pierre-Louis Bossart");
441MODULE_LICENSE("GPL v2");
442MODULE_ALIAS("platform:sof_pcm512x");
443MODULE_IMPORT_NS("SND_SOC_INTEL_HDA_DSP_COMMON");
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2// Copyright(c) 2018-2020 Intel Corporation.
  3
  4/*
  5 * Intel SOF Machine Driver for Intel platforms with TI PCM512x codec,
  6 * e.g. Up or Up2 with Hifiberry DAC+ HAT
  7 */
  8#include <linux/clk.h>
  9#include <linux/dmi.h>
 10#include <linux/i2c.h>
 11#include <linux/input.h>
 12#include <linux/module.h>
 13#include <linux/platform_device.h>
 14#include <linux/types.h>
 15#include <sound/core.h>
 16#include <sound/jack.h>
 17#include <sound/pcm.h>
 18#include <sound/pcm_params.h>
 19#include <sound/soc.h>
 20#include <sound/soc-acpi.h>
 21#include "../../codecs/pcm512x.h"
 22#include "../common/soc-intel-quirks.h"
 23#include "hda_dsp_common.h"
 24
 25#define NAME_SIZE 32
 26
 27#define SOF_PCM512X_SSP_CODEC(quirk)		((quirk) & GENMASK(3, 0))
 28#define SOF_PCM512X_SSP_CODEC_MASK			(GENMASK(3, 0))
 
 
 29
 30#define IDISP_CODEC_MASK	0x4
 31
 32/* Default: SSP5 */
 33static unsigned long sof_pcm512x_quirk = SOF_PCM512X_SSP_CODEC(5);
 
 
 
 34
 35static bool is_legacy_cpu;
 36
 37struct sof_hdmi_pcm {
 38	struct list_head head;
 39	struct snd_soc_dai *codec_dai;
 40	int device;
 41};
 42
 43struct sof_card_private {
 44	struct list_head hdmi_pcm_list;
 45	bool idisp_codec;
 46};
 47
 48static int sof_pcm512x_quirk_cb(const struct dmi_system_id *id)
 49{
 50	sof_pcm512x_quirk = (unsigned long)id->driver_data;
 51	return 1;
 52}
 53
 54static const struct dmi_system_id sof_pcm512x_quirk_table[] = {
 55	{
 56		.callback = sof_pcm512x_quirk_cb,
 57		.matches = {
 58			DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
 59			DMI_MATCH(DMI_PRODUCT_NAME, "UP-CHT01"),
 60		},
 61		.driver_data = (void *)(SOF_PCM512X_SSP_CODEC(2)),
 62	},
 63	{}
 64};
 65
 66static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd)
 67{
 68	struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
 69	struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
 70	struct sof_hdmi_pcm *pcm;
 71
 72	pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
 73	if (!pcm)
 74		return -ENOMEM;
 75
 76	/* dai_link id is 1:1 mapped to the PCM device */
 77	pcm->device = rtd->dai_link->id;
 78	pcm->codec_dai = dai;
 79
 80	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
 81
 82	return 0;
 83}
 84
 85static int sof_pcm512x_codec_init(struct snd_soc_pcm_runtime *rtd)
 86{
 87	struct snd_soc_component *codec = asoc_rtd_to_codec(rtd, 0)->component;
 88
 89	snd_soc_component_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
 90	snd_soc_component_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
 91	snd_soc_component_update_bits(codec, PCM512x_GPIO_CONTROL_1,
 92				      0x08, 0x08);
 93
 94	return 0;
 95}
 96
 97static int aif1_startup(struct snd_pcm_substream *substream)
 98{
 99	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
100	struct snd_soc_component *codec = asoc_rtd_to_codec(rtd, 0)->component;
101
102	snd_soc_component_update_bits(codec, PCM512x_GPIO_CONTROL_1,
103				      0x08, 0x08);
104
105	return 0;
106}
107
108static void aif1_shutdown(struct snd_pcm_substream *substream)
109{
110	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
111	struct snd_soc_component *codec = asoc_rtd_to_codec(rtd, 0)->component;
112
113	snd_soc_component_update_bits(codec, PCM512x_GPIO_CONTROL_1,
114				      0x08, 0x00);
115}
116
117static const struct snd_soc_ops sof_pcm512x_ops = {
118	.startup = aif1_startup,
119	.shutdown = aif1_shutdown,
120};
121
122static struct snd_soc_dai_link_component platform_component[] = {
123	{
124		/* name might be overridden during probe */
125		.name = "0000:00:1f.3"
126	}
127};
128
129static int sof_card_late_probe(struct snd_soc_card *card)
130{
131	struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
132	struct sof_hdmi_pcm *pcm;
133
134	/* HDMI is not supported by SOF on Baytrail/CherryTrail */
135	if (is_legacy_cpu)
136		return 0;
137
138	if (list_empty(&ctx->hdmi_pcm_list))
139		return -EINVAL;
140
141	if (!ctx->idisp_codec)
142		return 0;
143
144	pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm, head);
145
146	return hda_dsp_hdmi_build_controls(card, pcm->codec_dai->component);
147}
148
149static const struct snd_kcontrol_new sof_controls[] = {
150	SOC_DAPM_PIN_SWITCH("Ext Spk"),
151};
152
153static const struct snd_soc_dapm_widget sof_widgets[] = {
154	SND_SOC_DAPM_SPK("Ext Spk", NULL),
155};
156
157static const struct snd_soc_dapm_widget dmic_widgets[] = {
158	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
159};
160
161static const struct snd_soc_dapm_route sof_map[] = {
162	/* Speaker */
163	{"Ext Spk", NULL, "OUTR"},
164	{"Ext Spk", NULL, "OUTL"},
165};
166
167static const struct snd_soc_dapm_route dmic_map[] = {
168	/* digital mics */
169	{"DMic", NULL, "SoC DMIC"},
170};
171
172static int dmic_init(struct snd_soc_pcm_runtime *rtd)
173{
174	struct snd_soc_card *card = rtd->card;
175	int ret;
176
177	ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
178					ARRAY_SIZE(dmic_widgets));
179	if (ret) {
180		dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
181		/* Don't need to add routes if widget addition failed */
182		return ret;
183	}
184
185	ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
186				      ARRAY_SIZE(dmic_map));
187
188	if (ret)
189		dev_err(card->dev, "DMic map addition failed: %d\n", ret);
190
191	return ret;
192}
193
194/* sof audio machine driver for pcm512x codec */
195static struct snd_soc_card sof_audio_card_pcm512x = {
196	.name = "pcm512x",
197	.owner = THIS_MODULE,
198	.controls = sof_controls,
199	.num_controls = ARRAY_SIZE(sof_controls),
200	.dapm_widgets = sof_widgets,
201	.num_dapm_widgets = ARRAY_SIZE(sof_widgets),
202	.dapm_routes = sof_map,
203	.num_dapm_routes = ARRAY_SIZE(sof_map),
204	.fully_routed = true,
205	.late_probe = sof_card_late_probe,
206};
207
208SND_SOC_DAILINK_DEF(pcm512x_component,
209	DAILINK_COMP_ARRAY(COMP_CODEC("i2c-104C5122:00", "pcm512x-hifi")));
210SND_SOC_DAILINK_DEF(dmic_component,
211	DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
212
213static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
214							  int ssp_codec,
215							  int dmic_be_num,
216							  int hdmi_num,
217							  bool idisp_codec)
218{
219	struct snd_soc_dai_link_component *idisp_components;
220	struct snd_soc_dai_link_component *cpus;
221	struct snd_soc_dai_link *links;
222	int i, id = 0;
223
224	links = devm_kcalloc(dev, sof_audio_card_pcm512x.num_links,
225			sizeof(struct snd_soc_dai_link), GFP_KERNEL);
226	cpus = devm_kcalloc(dev, sof_audio_card_pcm512x.num_links,
227			sizeof(struct snd_soc_dai_link_component), GFP_KERNEL);
228	if (!links || !cpus)
229		goto devm_err;
230
231	/* codec SSP */
232	links[id].name = devm_kasprintf(dev, GFP_KERNEL,
233					"SSP%d-Codec", ssp_codec);
234	if (!links[id].name)
235		goto devm_err;
236
237	links[id].id = id;
238	links[id].codecs = pcm512x_component;
239	links[id].num_codecs = ARRAY_SIZE(pcm512x_component);
240	links[id].platforms = platform_component;
241	links[id].num_platforms = ARRAY_SIZE(platform_component);
242	links[id].init = sof_pcm512x_codec_init;
243	links[id].ops = &sof_pcm512x_ops;
244	links[id].nonatomic = true;
245	links[id].dpcm_playback = 1;
246	/*
247	 * capture only supported with specific versions of the Hifiberry DAC+
248	 * links[id].dpcm_capture = 1;
249	 */
 
 
250	links[id].no_pcm = 1;
251	links[id].cpus = &cpus[id];
252	links[id].num_cpus = 1;
253	if (is_legacy_cpu) {
254		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
255							  "ssp%d-port",
256							  ssp_codec);
257		if (!links[id].cpus->dai_name)
258			goto devm_err;
259	} else {
260		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
261							  "SSP%d Pin",
262							  ssp_codec);
263		if (!links[id].cpus->dai_name)
264			goto devm_err;
265	}
266	id++;
267
268	/* dmic */
269	if (dmic_be_num > 0) {
270		/* at least we have dmic01 */
271		links[id].name = "dmic01";
272		links[id].cpus = &cpus[id];
273		links[id].cpus->dai_name = "DMIC01 Pin";
274		links[id].init = dmic_init;
275		if (dmic_be_num > 1) {
276			/* set up 2 BE links at most */
277			links[id + 1].name = "dmic16k";
278			links[id + 1].cpus = &cpus[id + 1];
279			links[id + 1].cpus->dai_name = "DMIC16k Pin";
280			dmic_be_num = 2;
281		}
282	}
283
284	for (i = 0; i < dmic_be_num; i++) {
285		links[id].id = id;
286		links[id].num_cpus = 1;
287		links[id].codecs = dmic_component;
288		links[id].num_codecs = ARRAY_SIZE(dmic_component);
289		links[id].platforms = platform_component;
290		links[id].num_platforms = ARRAY_SIZE(platform_component);
291		links[id].ignore_suspend = 1;
292		links[id].dpcm_capture = 1;
293		links[id].no_pcm = 1;
294		id++;
295	}
296
297	/* HDMI */
298	if (hdmi_num > 0) {
299		idisp_components = devm_kcalloc(dev, hdmi_num,
300				sizeof(struct snd_soc_dai_link_component),
301				GFP_KERNEL);
302		if (!idisp_components)
303			goto devm_err;
304	}
305	for (i = 1; i <= hdmi_num; i++) {
306		links[id].name = devm_kasprintf(dev, GFP_KERNEL,
307						"iDisp%d", i);
308		if (!links[id].name)
309			goto devm_err;
310
311		links[id].id = id;
312		links[id].cpus = &cpus[id];
313		links[id].num_cpus = 1;
314		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
315							  "iDisp%d Pin", i);
316		if (!links[id].cpus->dai_name)
317			goto devm_err;
318
319		/*
320		 * topology cannot be loaded if codec is missing, so
321		 * use the dummy codec if needed
322		 */
323		if (idisp_codec) {
324			idisp_components[i - 1].name = "ehdaudio0D2";
325			idisp_components[i - 1].dai_name =
326				devm_kasprintf(dev, GFP_KERNEL,
327					       "intel-hdmi-hifi%d", i);
328		} else {
329			idisp_components[i - 1].name = "snd-soc-dummy";
330			idisp_components[i - 1].dai_name = "snd-soc-dummy-dai";
331		}
332		if (!idisp_components[i - 1].dai_name)
333			goto devm_err;
334
335		links[id].codecs = &idisp_components[i - 1];
336		links[id].num_codecs = 1;
337		links[id].platforms = platform_component;
338		links[id].num_platforms = ARRAY_SIZE(platform_component);
339		links[id].init = sof_hdmi_init;
340		links[id].dpcm_playback = 1;
341		links[id].no_pcm = 1;
342		id++;
343	}
344
345	return links;
346devm_err:
347	return NULL;
348}
349
350static int sof_audio_probe(struct platform_device *pdev)
351{
352	struct snd_soc_acpi_mach *mach = pdev->dev.platform_data;
353	struct snd_soc_dai_link *dai_links;
354	struct sof_card_private *ctx;
355	int dmic_be_num, hdmi_num;
356	int ret, ssp_codec;
357
358	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
359	if (!ctx)
360		return -ENOMEM;
361
362	hdmi_num = 0;
363	if (soc_intel_is_byt() || soc_intel_is_cht()) {
364		is_legacy_cpu = true;
365		dmic_be_num = 0;
366		/* default quirk for legacy cpu */
367		sof_pcm512x_quirk = SOF_PCM512X_SSP_CODEC(2);
368	} else {
369		dmic_be_num = 2;
370		if (mach->mach_params.common_hdmi_codec_drv &&
371		    (mach->mach_params.codec_mask & IDISP_CODEC_MASK))
372			ctx->idisp_codec = true;
373
374		/* links are always present in topology */
375		hdmi_num = 3;
376	}
377
378	dmi_check_system(sof_pcm512x_quirk_table);
379
380	dev_dbg(&pdev->dev, "sof_pcm512x_quirk = %lx\n", sof_pcm512x_quirk);
381
382	ssp_codec = sof_pcm512x_quirk & SOF_PCM512X_SSP_CODEC_MASK;
383
 
 
 
384	/* compute number of dai links */
385	sof_audio_card_pcm512x.num_links = 1 + dmic_be_num + hdmi_num;
386
387	dai_links = sof_card_dai_links_create(&pdev->dev, ssp_codec,
388					      dmic_be_num, hdmi_num,
389					      ctx->idisp_codec);
390	if (!dai_links)
391		return -ENOMEM;
392
393	sof_audio_card_pcm512x.dai_link = dai_links;
394
395	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
396
397	sof_audio_card_pcm512x.dev = &pdev->dev;
398
399	/* set platform name for each dailink */
400	ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_pcm512x,
401						    mach->mach_params.platform);
402	if (ret)
403		return ret;
404
405	snd_soc_card_set_drvdata(&sof_audio_card_pcm512x, ctx);
406
407	return devm_snd_soc_register_card(&pdev->dev,
408					  &sof_audio_card_pcm512x);
409}
410
411static int sof_pcm512x_remove(struct platform_device *pdev)
412{
413	struct snd_soc_card *card = platform_get_drvdata(pdev);
414	struct snd_soc_component *component = NULL;
415
416	for_each_card_components(card, component) {
417		if (!strcmp(component->name, pcm512x_component[0].name)) {
418			snd_soc_component_set_jack(component, NULL, NULL);
419			break;
420		}
421	}
422
423	return 0;
424}
425
426static struct platform_driver sof_audio = {
427	.probe = sof_audio_probe,
428	.remove = sof_pcm512x_remove,
429	.driver = {
430		.name = "sof_pcm512x",
431		.pm = &snd_soc_pm_ops,
432	},
433};
434module_platform_driver(sof_audio)
435
436MODULE_DESCRIPTION("ASoC Intel(R) SOF + PCM512x Machine driver");
437MODULE_AUTHOR("Pierre-Louis Bossart");
438MODULE_LICENSE("GPL v2");
439MODULE_ALIAS("platform:sof_pcm512x");