18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
28c2ecf20Sopenharmony_ci//
38c2ecf20Sopenharmony_ci// phycore-ac97.c  --  SoC audio for imx_phycore in AC97 mode
48c2ecf20Sopenharmony_ci//
58c2ecf20Sopenharmony_ci// Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/module.h>
88c2ecf20Sopenharmony_ci#include <linux/moduleparam.h>
98c2ecf20Sopenharmony_ci#include <linux/device.h>
108c2ecf20Sopenharmony_ci#include <linux/i2c.h>
118c2ecf20Sopenharmony_ci#include <sound/core.h>
128c2ecf20Sopenharmony_ci#include <sound/pcm.h>
138c2ecf20Sopenharmony_ci#include <sound/soc.h>
148c2ecf20Sopenharmony_ci#include <asm/mach-types.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include "imx-audmux.h"
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistatic struct snd_soc_card imx_phycore;
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistatic const struct snd_soc_ops imx_phycore_hifi_ops = {
218c2ecf20Sopenharmony_ci};
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(hifi,
248c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_CPU("imx-ssi.0")),
258c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-hifi")),
268c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_PLATFORM("imx-ssi.0")));
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistatic struct snd_soc_dai_link imx_phycore_dai_ac97[] = {
298c2ecf20Sopenharmony_ci	{
308c2ecf20Sopenharmony_ci		.name		= "HiFi",
318c2ecf20Sopenharmony_ci		.stream_name	= "HiFi",
328c2ecf20Sopenharmony_ci		.ops		= &imx_phycore_hifi_ops,
338c2ecf20Sopenharmony_ci		SND_SOC_DAILINK_REG(hifi),
348c2ecf20Sopenharmony_ci	},
358c2ecf20Sopenharmony_ci};
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic struct snd_soc_card imx_phycore = {
388c2ecf20Sopenharmony_ci	.name		= "PhyCORE-ac97-audio",
398c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,
408c2ecf20Sopenharmony_ci	.dai_link	= imx_phycore_dai_ac97,
418c2ecf20Sopenharmony_ci	.num_links	= ARRAY_SIZE(imx_phycore_dai_ac97),
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic struct platform_device *imx_phycore_snd_ac97_device;
458c2ecf20Sopenharmony_cistatic struct platform_device *imx_phycore_snd_device;
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistatic int __init imx_phycore_init(void)
488c2ecf20Sopenharmony_ci{
498c2ecf20Sopenharmony_ci	int ret;
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	if (machine_is_pca100()) {
528c2ecf20Sopenharmony_ci		imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
538c2ecf20Sopenharmony_ci			IMX_AUDMUX_V1_PCR_SYN | /* 4wire mode */
548c2ecf20Sopenharmony_ci			IMX_AUDMUX_V1_PCR_TFCSEL(3) |
558c2ecf20Sopenharmony_ci			IMX_AUDMUX_V1_PCR_TCLKDIR | /* clock is output */
568c2ecf20Sopenharmony_ci			IMX_AUDMUX_V1_PCR_RXDSEL(3));
578c2ecf20Sopenharmony_ci		imx_audmux_v1_configure_port(3,
588c2ecf20Sopenharmony_ci			IMX_AUDMUX_V1_PCR_SYN | /* 4wire mode */
598c2ecf20Sopenharmony_ci			IMX_AUDMUX_V1_PCR_TFCSEL(0) |
608c2ecf20Sopenharmony_ci			IMX_AUDMUX_V1_PCR_TFSDIR |
618c2ecf20Sopenharmony_ci			IMX_AUDMUX_V1_PCR_RXDSEL(0));
628c2ecf20Sopenharmony_ci	} else if (machine_is_pcm043()) {
638c2ecf20Sopenharmony_ci		imx_audmux_v2_configure_port(3,
648c2ecf20Sopenharmony_ci			IMX_AUDMUX_V2_PTCR_SYN | /* 4wire mode */
658c2ecf20Sopenharmony_ci			IMX_AUDMUX_V2_PTCR_TFSEL(0) |
668c2ecf20Sopenharmony_ci			IMX_AUDMUX_V2_PTCR_TFSDIR,
678c2ecf20Sopenharmony_ci			IMX_AUDMUX_V2_PDCR_RXDSEL(0));
688c2ecf20Sopenharmony_ci		imx_audmux_v2_configure_port(0,
698c2ecf20Sopenharmony_ci			IMX_AUDMUX_V2_PTCR_SYN | /* 4wire mode */
708c2ecf20Sopenharmony_ci			IMX_AUDMUX_V2_PTCR_TCSEL(3) |
718c2ecf20Sopenharmony_ci			IMX_AUDMUX_V2_PTCR_TCLKDIR, /* clock is output */
728c2ecf20Sopenharmony_ci			IMX_AUDMUX_V2_PDCR_RXDSEL(3));
738c2ecf20Sopenharmony_ci	} else {
748c2ecf20Sopenharmony_ci		/* return happy. We might run on a totally different machine */
758c2ecf20Sopenharmony_ci		return 0;
768c2ecf20Sopenharmony_ci	}
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	imx_phycore_snd_ac97_device = platform_device_alloc("soc-audio", -1);
798c2ecf20Sopenharmony_ci	if (!imx_phycore_snd_ac97_device)
808c2ecf20Sopenharmony_ci		return -ENOMEM;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	platform_set_drvdata(imx_phycore_snd_ac97_device, &imx_phycore);
838c2ecf20Sopenharmony_ci	ret = platform_device_add(imx_phycore_snd_ac97_device);
848c2ecf20Sopenharmony_ci	if (ret)
858c2ecf20Sopenharmony_ci		goto fail1;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	imx_phycore_snd_device = platform_device_alloc("wm9712-codec", -1);
888c2ecf20Sopenharmony_ci	if (!imx_phycore_snd_device) {
898c2ecf20Sopenharmony_ci		ret = -ENOMEM;
908c2ecf20Sopenharmony_ci		goto fail2;
918c2ecf20Sopenharmony_ci	}
928c2ecf20Sopenharmony_ci	ret = platform_device_add(imx_phycore_snd_device);
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	if (ret) {
958c2ecf20Sopenharmony_ci		printk(KERN_ERR "ASoC: Platform device allocation failed\n");
968c2ecf20Sopenharmony_ci		goto fail3;
978c2ecf20Sopenharmony_ci	}
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	return 0;
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_cifail3:
1028c2ecf20Sopenharmony_ci	platform_device_put(imx_phycore_snd_device);
1038c2ecf20Sopenharmony_cifail2:
1048c2ecf20Sopenharmony_ci	platform_device_del(imx_phycore_snd_ac97_device);
1058c2ecf20Sopenharmony_cifail1:
1068c2ecf20Sopenharmony_ci	platform_device_put(imx_phycore_snd_ac97_device);
1078c2ecf20Sopenharmony_ci	return ret;
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistatic void __exit imx_phycore_exit(void)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	platform_device_unregister(imx_phycore_snd_device);
1138c2ecf20Sopenharmony_ci	platform_device_unregister(imx_phycore_snd_ac97_device);
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cilate_initcall(imx_phycore_init);
1178c2ecf20Sopenharmony_cimodule_exit(imx_phycore_exit);
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ciMODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
1208c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("PhyCORE ALSA SoC driver");
1218c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
122