blob: 3665f612819d4bd2d443b0e7072cf9753ee1905b [file] [log] [blame]
Jon Smirla9262c42009-05-26 08:34:12 -04001/*
2 * Phytec pcm030 driver for the PSC of the Freescale MPC52xx
3 * configured as AC97 interface
4 *
5 * Copyright 2008 Jon Smirl, Digispeaker
6 * Author: Jon Smirl <jonsmirl@gmail.com>
7 *
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
11 */
12
13#include <linux/init.h>
14#include <linux/module.h>
Jon Smirla9262c42009-05-26 08:34:12 -040015#include <linux/device.h>
Jon Smirla9262c42009-05-26 08:34:12 -040016#include <linux/of_device.h>
17#include <linux/of_platform.h>
Jon Smirla9262c42009-05-26 08:34:12 -040018
Jon Smirla9262c42009-05-26 08:34:12 -040019#include <sound/soc.h>
Jon Smirla9262c42009-05-26 08:34:12 -040020
21#include "mpc5200_dma.h"
Jon Smirla9262c42009-05-26 08:34:12 -040022
Takashi Iwaiafc5e652009-08-07 16:33:53 +020023#define DRV_NAME "pcm030-audio-fabric"
24
Eric Millbrandtc912fa92012-09-20 10:36:45 -040025struct pcm030_audio_data {
26 struct snd_soc_card *card;
27 struct platform_device *codec_device;
28};
29
Jon Smirla9262c42009-05-26 08:34:12 -040030static struct snd_soc_dai_link pcm030_fabric_dai[] = {
31{
Eric Millbrandtc73adc72012-10-10 10:10:08 -040032 .name = "AC97.0",
Jon Smirla9262c42009-05-26 08:34:12 -040033 .stream_name = "AC97 Analog",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000034 .codec_dai_name = "wm9712-hifi",
35 .cpu_dai_name = "mpc5200-psc-ac97.0",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000036 .codec_name = "wm9712-codec",
Jon Smirla9262c42009-05-26 08:34:12 -040037},
38{
Eric Millbrandtc73adc72012-10-10 10:10:08 -040039 .name = "AC97.1",
Jon Smirla9262c42009-05-26 08:34:12 -040040 .stream_name = "AC97 IEC958",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000041 .codec_dai_name = "wm9712-aux",
42 .cpu_dai_name = "mpc5200-psc-ac97.1",
Liam Girdwoode94be5f2010-10-26 20:07:43 +010043 .codec_name = "wm9712-codec",
Jon Smirla9262c42009-05-26 08:34:12 -040044},
45};
46
Eric Millbrandt08401162012-09-20 10:36:44 -040047static struct snd_soc_card pcm030_card = {
Axel Lin4c3c5df2011-12-22 21:04:54 +080048 .name = "pcm030",
49 .owner = THIS_MODULE,
50 .dai_link = pcm030_fabric_dai,
51 .num_links = ARRAY_SIZE(pcm030_fabric_dai),
52};
53
Markus Pargmann34913fd2013-03-10 19:33:06 +010054static int pcm030_fabric_probe(struct platform_device *op)
Jon Smirla9262c42009-05-26 08:34:12 -040055{
Eric Millbrandt08401162012-09-20 10:36:44 -040056 struct device_node *np = op->dev.of_node;
57 struct device_node *platform_np;
58 struct snd_soc_card *card = &pcm030_card;
Eric Millbrandtc912fa92012-09-20 10:36:45 -040059 struct pcm030_audio_data *pdata;
Eric Millbrandt08401162012-09-20 10:36:44 -040060 int ret;
61 int i;
Jon Smirla9262c42009-05-26 08:34:12 -040062
Grant Likely71a157e2010-02-01 21:34:14 -070063 if (!of_machine_is_compatible("phytec,pcm030"))
Jon Smirla9262c42009-05-26 08:34:12 -040064 return -ENODEV;
65
Eric Millbrandtc912fa92012-09-20 10:36:45 -040066 pdata = devm_kzalloc(&op->dev, sizeof(struct pcm030_audio_data),
67 GFP_KERNEL);
68 if (!pdata)
69 return -ENOMEM;
70
Eric Millbrandt08401162012-09-20 10:36:44 -040071 card->dev = &op->dev;
Eric Millbrandtc912fa92012-09-20 10:36:45 -040072
73 pdata->card = card;
Eric Millbrandt08401162012-09-20 10:36:44 -040074
75 platform_np = of_parse_phandle(np, "asoc-platform", 0);
76 if (!platform_np) {
77 dev_err(&op->dev, "ac97 not registered\n");
Jon Smirla9262c42009-05-26 08:34:12 -040078 return -ENODEV;
79 }
80
Eric Millbrandt08401162012-09-20 10:36:44 -040081 for (i = 0; i < card->num_links; i++)
82 card->dai_link[i].platform_of_node = platform_np;
Jon Smirla9262c42009-05-26 08:34:12 -040083
Eric Millbrandtc912fa92012-09-20 10:36:45 -040084 ret = request_module("snd-soc-wm9712");
85 if (ret)
86 dev_err(&op->dev, "request_module returned: %d\n", ret);
87
88 pdata->codec_device = platform_device_alloc("wm9712-codec", -1);
89 if (!pdata->codec_device)
90 dev_err(&op->dev, "platform_device_alloc() failed\n");
91
92 ret = platform_device_add(pdata->codec_device);
93 if (ret)
94 dev_err(&op->dev, "platform_device_add() failed: %d\n", ret);
95
Eric Millbrandt08401162012-09-20 10:36:44 -040096 ret = snd_soc_register_card(card);
97 if (ret)
98 dev_err(&op->dev, "snd_soc_register_card() failed: %d\n", ret);
99
Wei Yongjun6c7ef412013-11-09 08:41:14 +0800100 platform_set_drvdata(op, pdata);
101
Eric Millbrandt08401162012-09-20 10:36:44 -0400102 return ret;
Jon Smirla9262c42009-05-26 08:34:12 -0400103}
104
Bill Pembertona0a3d512012-12-07 09:26:16 -0500105static int pcm030_fabric_remove(struct platform_device *op)
Eric Millbrandt08401162012-09-20 10:36:44 -0400106{
Eric Millbrandtc912fa92012-09-20 10:36:45 -0400107 struct pcm030_audio_data *pdata = platform_get_drvdata(op);
Eric Millbrandt08401162012-09-20 10:36:44 -0400108 int ret;
109
Eric Millbrandtc912fa92012-09-20 10:36:45 -0400110 ret = snd_soc_unregister_card(pdata->card);
111 platform_device_unregister(pdata->codec_device);
Eric Millbrandt08401162012-09-20 10:36:44 -0400112
113 return ret;
114}
115
116static struct of_device_id pcm030_audio_match[] = {
117 { .compatible = "phytec,pcm030-audio-fabric", },
118 {}
119};
120MODULE_DEVICE_TABLE(of, pcm030_audio_match);
121
122static struct platform_driver pcm030_fabric_driver = {
123 .probe = pcm030_fabric_probe,
Bill Pembertona0a3d512012-12-07 09:26:16 -0500124 .remove = pcm030_fabric_remove,
Eric Millbrandt08401162012-09-20 10:36:44 -0400125 .driver = {
126 .name = DRV_NAME,
127 .owner = THIS_MODULE,
128 .of_match_table = pcm030_audio_match,
129 },
130};
131
132module_platform_driver(pcm030_fabric_driver);
Jon Smirla9262c42009-05-26 08:34:12 -0400133
134
135MODULE_AUTHOR("Jon Smirl <jonsmirl@gmail.com>");
136MODULE_DESCRIPTION(DRV_NAME ": mpc5200 pcm030 fabric driver");
137MODULE_LICENSE("GPL");
138