1// SPDX-License-Identifier: GPL-2.0+
2//
3// phycore-ac97.c  --  SoC audio for imx_phycore in AC97 mode
4//
5// Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
6
7#include <linux/module.h>
8#include <linux/moduleparam.h>
9#include <linux/device.h>
10#include <linux/i2c.h>
11#include <sound/core.h>
12#include <sound/pcm.h>
13#include <sound/soc.h>
14#include <asm/mach-types.h>
15
16#include "imx-audmux.h"
17
18static struct snd_soc_card imx_phycore;
19
20static const struct snd_soc_ops imx_phycore_hifi_ops = {
21};
22
23SND_SOC_DAILINK_DEFS(hifi,
24	DAILINK_COMP_ARRAY(COMP_CPU("imx-ssi.0")),
25	DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-hifi")),
26	DAILINK_COMP_ARRAY(COMP_PLATFORM("imx-ssi.0")));
27
28static struct snd_soc_dai_link imx_phycore_dai_ac97[] = {
29	{
30		.name		= "HiFi",
31		.stream_name	= "HiFi",
32		.ops		= &imx_phycore_hifi_ops,
33		SND_SOC_DAILINK_REG(hifi),
34	},
35};
36
37static struct snd_soc_card imx_phycore = {
38	.name		= "PhyCORE-ac97-audio",
39	.owner		= THIS_MODULE,
40	.dai_link	= imx_phycore_dai_ac97,
41	.num_links	= ARRAY_SIZE(imx_phycore_dai_ac97),
42};
43
44static struct platform_device *imx_phycore_snd_ac97_device;
45static struct platform_device *imx_phycore_snd_device;
46
47static int __init imx_phycore_init(void)
48{
49	int ret;
50
51	if (machine_is_pca100()) {
52		imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
53			IMX_AUDMUX_V1_PCR_SYN | /* 4wire mode */
54			IMX_AUDMUX_V1_PCR_TFCSEL(3) |
55			IMX_AUDMUX_V1_PCR_TCLKDIR | /* clock is output */
56			IMX_AUDMUX_V1_PCR_RXDSEL(3));
57		imx_audmux_v1_configure_port(3,
58			IMX_AUDMUX_V1_PCR_SYN | /* 4wire mode */
59			IMX_AUDMUX_V1_PCR_TFCSEL(0) |
60			IMX_AUDMUX_V1_PCR_TFSDIR |
61			IMX_AUDMUX_V1_PCR_RXDSEL(0));
62	} else if (machine_is_pcm043()) {
63		imx_audmux_v2_configure_port(3,
64			IMX_AUDMUX_V2_PTCR_SYN | /* 4wire mode */
65			IMX_AUDMUX_V2_PTCR_TFSEL(0) |
66			IMX_AUDMUX_V2_PTCR_TFSDIR,
67			IMX_AUDMUX_V2_PDCR_RXDSEL(0));
68		imx_audmux_v2_configure_port(0,
69			IMX_AUDMUX_V2_PTCR_SYN | /* 4wire mode */
70			IMX_AUDMUX_V2_PTCR_TCSEL(3) |
71			IMX_AUDMUX_V2_PTCR_TCLKDIR, /* clock is output */
72			IMX_AUDMUX_V2_PDCR_RXDSEL(3));
73	} else {
74		/* return happy. We might run on a totally different machine */
75		return 0;
76	}
77
78	imx_phycore_snd_ac97_device = platform_device_alloc("soc-audio", -1);
79	if (!imx_phycore_snd_ac97_device)
80		return -ENOMEM;
81
82	platform_set_drvdata(imx_phycore_snd_ac97_device, &imx_phycore);
83	ret = platform_device_add(imx_phycore_snd_ac97_device);
84	if (ret)
85		goto fail1;
86
87	imx_phycore_snd_device = platform_device_alloc("wm9712-codec", -1);
88	if (!imx_phycore_snd_device) {
89		ret = -ENOMEM;
90		goto fail2;
91	}
92	ret = platform_device_add(imx_phycore_snd_device);
93
94	if (ret) {
95		printk(KERN_ERR "ASoC: Platform device allocation failed\n");
96		goto fail3;
97	}
98
99	return 0;
100
101fail3:
102	platform_device_put(imx_phycore_snd_device);
103fail2:
104	platform_device_del(imx_phycore_snd_ac97_device);
105fail1:
106	platform_device_put(imx_phycore_snd_ac97_device);
107	return ret;
108}
109
110static void __exit imx_phycore_exit(void)
111{
112	platform_device_unregister(imx_phycore_snd_device);
113	platform_device_unregister(imx_phycore_snd_ac97_device);
114}
115
116late_initcall(imx_phycore_init);
117module_exit(imx_phycore_exit);
118
119MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
120MODULE_DESCRIPTION("PhyCORE ALSA SoC driver");
121MODULE_LICENSE("GPL");
122