Commit | Line | Data |
---|---|---|
a9262c4f JS |
1 | /* |
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> | |
a9262c4f | 15 | #include <linux/device.h> |
a9262c4f JS |
16 | #include <linux/of_device.h> |
17 | #include <linux/of_platform.h> | |
a9262c4f | 18 | |
a9262c4f | 19 | #include <sound/soc.h> |
a9262c4f JS |
20 | |
21 | #include "mpc5200_dma.h" | |
a9262c4f | 22 | |
afc5e652 TI |
23 | #define DRV_NAME "pcm030-audio-fabric" |
24 | ||
c912fa91 EM |
25 | struct pcm030_audio_data { |
26 | struct snd_soc_card *card; | |
27 | struct platform_device *codec_device; | |
28 | }; | |
29 | ||
a9262c4f JS |
30 | static struct snd_soc_dai_link pcm030_fabric_dai[] = { |
31 | { | |
c73adc74 | 32 | .name = "AC97.0", |
a9262c4f | 33 | .stream_name = "AC97 Analog", |
f0fba2ad LG |
34 | .codec_dai_name = "wm9712-hifi", |
35 | .cpu_dai_name = "mpc5200-psc-ac97.0", | |
f0fba2ad | 36 | .codec_name = "wm9712-codec", |
a9262c4f JS |
37 | }, |
38 | { | |
c73adc74 | 39 | .name = "AC97.1", |
a9262c4f | 40 | .stream_name = "AC97 IEC958", |
f0fba2ad LG |
41 | .codec_dai_name = "wm9712-aux", |
42 | .cpu_dai_name = "mpc5200-psc-ac97.1", | |
e94be5f3 | 43 | .codec_name = "wm9712-codec", |
a9262c4f JS |
44 | }, |
45 | }; | |
46 | ||
08401161 | 47 | static struct snd_soc_card pcm030_card = { |
4c3c5df0 AL |
48 | .name = "pcm030", |
49 | .owner = THIS_MODULE, | |
50 | .dai_link = pcm030_fabric_dai, | |
51 | .num_links = ARRAY_SIZE(pcm030_fabric_dai), | |
52 | }; | |
53 | ||
34913fd9 | 54 | static int pcm030_fabric_probe(struct platform_device *op) |
a9262c4f | 55 | { |
08401161 EM |
56 | struct device_node *np = op->dev.of_node; |
57 | struct device_node *platform_np; | |
58 | struct snd_soc_card *card = &pcm030_card; | |
c912fa91 | 59 | struct pcm030_audio_data *pdata; |
08401161 EM |
60 | int ret; |
61 | int i; | |
a9262c4f | 62 | |
71a157e8 | 63 | if (!of_machine_is_compatible("phytec,pcm030")) |
a9262c4f JS |
64 | return -ENODEV; |
65 | ||
c912fa91 EM |
66 | pdata = devm_kzalloc(&op->dev, sizeof(struct pcm030_audio_data), |
67 | GFP_KERNEL); | |
68 | if (!pdata) | |
69 | return -ENOMEM; | |
70 | ||
08401161 | 71 | card->dev = &op->dev; |
c912fa91 EM |
72 | |
73 | pdata->card = card; | |
08401161 EM |
74 | |
75 | platform_np = of_parse_phandle(np, "asoc-platform", 0); | |
76 | if (!platform_np) { | |
77 | dev_err(&op->dev, "ac97 not registered\n"); | |
a9262c4f JS |
78 | return -ENODEV; |
79 | } | |
80 | ||
08401161 EM |
81 | for (i = 0; i < card->num_links; i++) |
82 | card->dai_link[i].platform_of_node = platform_np; | |
a9262c4f | 83 | |
c912fa91 EM |
84 | 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 | ||
08401161 EM |
96 | ret = snd_soc_register_card(card); |
97 | if (ret) | |
98 | dev_err(&op->dev, "snd_soc_register_card() failed: %d\n", ret); | |
99 | ||
6c7ef410 WY |
100 | platform_set_drvdata(op, pdata); |
101 | ||
08401161 | 102 | return ret; |
a9262c4f JS |
103 | } |
104 | ||
a0a3d518 | 105 | static int pcm030_fabric_remove(struct platform_device *op) |
08401161 | 106 | { |
c912fa91 | 107 | struct pcm030_audio_data *pdata = platform_get_drvdata(op); |
08401161 EM |
108 | int ret; |
109 | ||
c912fa91 EM |
110 | ret = snd_soc_unregister_card(pdata->card); |
111 | platform_device_unregister(pdata->codec_device); | |
08401161 EM |
112 | |
113 | return ret; | |
114 | } | |
115 | ||
6ffa84df | 116 | static const struct of_device_id pcm030_audio_match[] = { |
08401161 EM |
117 | { .compatible = "phytec,pcm030-audio-fabric", }, |
118 | {} | |
119 | }; | |
120 | MODULE_DEVICE_TABLE(of, pcm030_audio_match); | |
121 | ||
122 | static struct platform_driver pcm030_fabric_driver = { | |
123 | .probe = pcm030_fabric_probe, | |
a0a3d518 | 124 | .remove = pcm030_fabric_remove, |
08401161 EM |
125 | .driver = { |
126 | .name = DRV_NAME, | |
08401161 EM |
127 | .of_match_table = pcm030_audio_match, |
128 | }, | |
129 | }; | |
130 | ||
131 | module_platform_driver(pcm030_fabric_driver); | |
a9262c4f JS |
132 | |
133 | ||
134 | MODULE_AUTHOR("Jon Smirl <jonsmirl@gmail.com>"); | |
135 | MODULE_DESCRIPTION(DRV_NAME ": mpc5200 pcm030 fabric driver"); | |
136 | MODULE_LICENSE("GPL"); | |
137 |