1a9262c4fSJon Smirl /*
2a9262c4fSJon Smirl  * Phytec pcm030 driver for the PSC of the Freescale MPC52xx
3a9262c4fSJon Smirl  * configured as AC97 interface
4a9262c4fSJon Smirl  *
5a9262c4fSJon Smirl  * Copyright 2008 Jon Smirl, Digispeaker
6a9262c4fSJon Smirl  * Author: Jon Smirl <jonsmirl@gmail.com>
7a9262c4fSJon Smirl  *
8a9262c4fSJon Smirl  * This file is licensed under the terms of the GNU General Public License
9a9262c4fSJon Smirl  * version 2. This program is licensed "as is" without any warranty of any
10a9262c4fSJon Smirl  * kind, whether express or implied.
11a9262c4fSJon Smirl  */
12a9262c4fSJon Smirl 
13a9262c4fSJon Smirl #include <linux/init.h>
14a9262c4fSJon Smirl #include <linux/module.h>
15a9262c4fSJon Smirl #include <linux/device.h>
16a9262c4fSJon Smirl #include <linux/of_device.h>
17a9262c4fSJon Smirl #include <linux/of_platform.h>
18a9262c4fSJon Smirl 
19a9262c4fSJon Smirl #include <sound/soc.h>
20a9262c4fSJon Smirl 
21a9262c4fSJon Smirl #include "mpc5200_dma.h"
22a9262c4fSJon Smirl 
23afc5e652STakashi Iwai #define DRV_NAME "pcm030-audio-fabric"
24afc5e652STakashi Iwai 
25c912fa91SEric Millbrandt struct pcm030_audio_data {
26c912fa91SEric Millbrandt 	struct snd_soc_card *card;
27c912fa91SEric Millbrandt 	struct platform_device *codec_device;
28c912fa91SEric Millbrandt };
29c912fa91SEric Millbrandt 
30a9262c4fSJon Smirl static struct snd_soc_dai_link pcm030_fabric_dai[] = {
31a9262c4fSJon Smirl {
32c73adc74SEric Millbrandt 	.name = "AC97.0",
33a9262c4fSJon Smirl 	.stream_name = "AC97 Analog",
34f0fba2adSLiam Girdwood 	.codec_dai_name = "wm9712-hifi",
35f0fba2adSLiam Girdwood 	.cpu_dai_name = "mpc5200-psc-ac97.0",
36f0fba2adSLiam Girdwood 	.codec_name = "wm9712-codec",
37a9262c4fSJon Smirl },
38a9262c4fSJon Smirl {
39c73adc74SEric Millbrandt 	.name = "AC97.1",
40a9262c4fSJon Smirl 	.stream_name = "AC97 IEC958",
41f0fba2adSLiam Girdwood 	.codec_dai_name = "wm9712-aux",
42f0fba2adSLiam Girdwood 	.cpu_dai_name = "mpc5200-psc-ac97.1",
43e94be5f3SLiam Girdwood 	.codec_name = "wm9712-codec",
44a9262c4fSJon Smirl },
45a9262c4fSJon Smirl };
46a9262c4fSJon Smirl 
4708401161SEric Millbrandt static struct snd_soc_card pcm030_card = {
484c3c5df0SAxel Lin 	.name = "pcm030",
494c3c5df0SAxel Lin 	.owner = THIS_MODULE,
504c3c5df0SAxel Lin 	.dai_link = pcm030_fabric_dai,
514c3c5df0SAxel Lin 	.num_links = ARRAY_SIZE(pcm030_fabric_dai),
524c3c5df0SAxel Lin };
534c3c5df0SAxel Lin 
5434913fd9SMarkus Pargmann static int pcm030_fabric_probe(struct platform_device *op)
55a9262c4fSJon Smirl {
5608401161SEric Millbrandt 	struct device_node *np = op->dev.of_node;
5708401161SEric Millbrandt 	struct device_node *platform_np;
5808401161SEric Millbrandt 	struct snd_soc_card *card = &pcm030_card;
59c912fa91SEric Millbrandt 	struct pcm030_audio_data *pdata;
6008401161SEric Millbrandt 	int ret;
6108401161SEric Millbrandt 	int i;
62a9262c4fSJon Smirl 
6371a157e8SGrant Likely 	if (!of_machine_is_compatible("phytec,pcm030"))
64a9262c4fSJon Smirl 		return -ENODEV;
65a9262c4fSJon Smirl 
66c912fa91SEric Millbrandt 	pdata = devm_kzalloc(&op->dev, sizeof(struct pcm030_audio_data),
67c912fa91SEric Millbrandt 			     GFP_KERNEL);
68c912fa91SEric Millbrandt 	if (!pdata)
69c912fa91SEric Millbrandt 		return -ENOMEM;
70c912fa91SEric Millbrandt 
7108401161SEric Millbrandt 	card->dev = &op->dev;
72c912fa91SEric Millbrandt 	platform_set_drvdata(op, pdata);
73c912fa91SEric Millbrandt 
74c912fa91SEric Millbrandt 	pdata->card = card;
7508401161SEric Millbrandt 
7608401161SEric Millbrandt 	platform_np = of_parse_phandle(np, "asoc-platform", 0);
7708401161SEric Millbrandt 	if (!platform_np) {
7808401161SEric Millbrandt 		dev_err(&op->dev, "ac97 not registered\n");
79a9262c4fSJon Smirl 		return -ENODEV;
80a9262c4fSJon Smirl 	}
81a9262c4fSJon Smirl 
8208401161SEric Millbrandt 	for (i = 0; i < card->num_links; i++)
8308401161SEric Millbrandt 		card->dai_link[i].platform_of_node = platform_np;
84a9262c4fSJon Smirl 
85c912fa91SEric Millbrandt 	ret = request_module("snd-soc-wm9712");
86c912fa91SEric Millbrandt 	if (ret)
87c912fa91SEric Millbrandt 		dev_err(&op->dev, "request_module returned: %d\n", ret);
88c912fa91SEric Millbrandt 
89c912fa91SEric Millbrandt 	pdata->codec_device = platform_device_alloc("wm9712-codec", -1);
90c912fa91SEric Millbrandt 	if (!pdata->codec_device)
91c912fa91SEric Millbrandt 		dev_err(&op->dev, "platform_device_alloc() failed\n");
92c912fa91SEric Millbrandt 
93c912fa91SEric Millbrandt 	ret = platform_device_add(pdata->codec_device);
94c912fa91SEric Millbrandt 	if (ret)
95c912fa91SEric Millbrandt 		dev_err(&op->dev, "platform_device_add() failed: %d\n", ret);
96c912fa91SEric Millbrandt 
9708401161SEric Millbrandt 	ret = snd_soc_register_card(card);
9808401161SEric Millbrandt 	if (ret)
9908401161SEric Millbrandt 		dev_err(&op->dev, "snd_soc_register_card() failed: %d\n", ret);
10008401161SEric Millbrandt 
10108401161SEric Millbrandt 	return ret;
102a9262c4fSJon Smirl }
103a9262c4fSJon Smirl 
104a0a3d518SBill Pemberton static int pcm030_fabric_remove(struct platform_device *op)
10508401161SEric Millbrandt {
106c912fa91SEric Millbrandt 	struct pcm030_audio_data *pdata = platform_get_drvdata(op);
10708401161SEric Millbrandt 	int ret;
10808401161SEric Millbrandt 
109c912fa91SEric Millbrandt 	ret = snd_soc_unregister_card(pdata->card);
110c912fa91SEric Millbrandt 	platform_device_unregister(pdata->codec_device);
11108401161SEric Millbrandt 
11208401161SEric Millbrandt 	return ret;
11308401161SEric Millbrandt }
11408401161SEric Millbrandt 
11508401161SEric Millbrandt static struct of_device_id pcm030_audio_match[] = {
11608401161SEric Millbrandt 	{ .compatible = "phytec,pcm030-audio-fabric", },
11708401161SEric Millbrandt 	{}
11808401161SEric Millbrandt };
11908401161SEric Millbrandt MODULE_DEVICE_TABLE(of, pcm030_audio_match);
12008401161SEric Millbrandt 
12108401161SEric Millbrandt static struct platform_driver pcm030_fabric_driver = {
12208401161SEric Millbrandt 	.probe		= pcm030_fabric_probe,
123a0a3d518SBill Pemberton 	.remove		= pcm030_fabric_remove,
12408401161SEric Millbrandt 	.driver		= {
12508401161SEric Millbrandt 		.name	= DRV_NAME,
12608401161SEric Millbrandt 		.owner	= THIS_MODULE,
12708401161SEric Millbrandt 		.of_match_table    = pcm030_audio_match,
12808401161SEric Millbrandt 	},
12908401161SEric Millbrandt };
13008401161SEric Millbrandt 
13108401161SEric Millbrandt module_platform_driver(pcm030_fabric_driver);
132a9262c4fSJon Smirl 
133a9262c4fSJon Smirl 
134a9262c4fSJon Smirl MODULE_AUTHOR("Jon Smirl <jonsmirl@gmail.com>");
135a9262c4fSJon Smirl MODULE_DESCRIPTION(DRV_NAME ": mpc5200 pcm030 fabric driver");
136a9262c4fSJon Smirl MODULE_LICENSE("GPL");
137a9262c4fSJon Smirl 
138