0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/init.h>
0010 #include <linux/module.h>
0011 #include <linux/device.h>
0012 #include <linux/of_device.h>
0013 #include <linux/of_platform.h>
0014
0015 #include <sound/soc.h>
0016
0017 #include "mpc5200_dma.h"
0018
0019 #define DRV_NAME "pcm030-audio-fabric"
0020
0021 struct pcm030_audio_data {
0022 struct snd_soc_card *card;
0023 struct platform_device *codec_device;
0024 };
0025
0026 SND_SOC_DAILINK_DEFS(analog,
0027 DAILINK_COMP_ARRAY(COMP_CPU("mpc5200-psc-ac97.0")),
0028 DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-hifi")),
0029 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0030
0031 SND_SOC_DAILINK_DEFS(iec958,
0032 DAILINK_COMP_ARRAY(COMP_CPU("mpc5200-psc-ac97.1")),
0033 DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-aux")),
0034 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0035
0036 static struct snd_soc_dai_link pcm030_fabric_dai[] = {
0037 {
0038 .name = "AC97.0",
0039 .stream_name = "AC97 Analog",
0040 SND_SOC_DAILINK_REG(analog),
0041 },
0042 {
0043 .name = "AC97.1",
0044 .stream_name = "AC97 IEC958",
0045 SND_SOC_DAILINK_REG(iec958),
0046 },
0047 };
0048
0049 static struct snd_soc_card pcm030_card = {
0050 .name = "pcm030",
0051 .owner = THIS_MODULE,
0052 .dai_link = pcm030_fabric_dai,
0053 .num_links = ARRAY_SIZE(pcm030_fabric_dai),
0054 };
0055
0056 static int pcm030_fabric_probe(struct platform_device *op)
0057 {
0058 struct device_node *np = op->dev.of_node;
0059 struct device_node *platform_np;
0060 struct snd_soc_card *card = &pcm030_card;
0061 struct pcm030_audio_data *pdata;
0062 struct snd_soc_dai_link *dai_link;
0063 int ret;
0064 int i;
0065
0066 if (!of_machine_is_compatible("phytec,pcm030"))
0067 return -ENODEV;
0068
0069 pdata = devm_kzalloc(&op->dev, sizeof(struct pcm030_audio_data),
0070 GFP_KERNEL);
0071 if (!pdata)
0072 return -ENOMEM;
0073
0074 card->dev = &op->dev;
0075
0076 pdata->card = card;
0077
0078 platform_np = of_parse_phandle(np, "asoc-platform", 0);
0079 if (!platform_np) {
0080 dev_err(&op->dev, "ac97 not registered\n");
0081 return -ENODEV;
0082 }
0083
0084 for_each_card_prelinks(card, i, dai_link)
0085 dai_link->platforms->of_node = platform_np;
0086
0087 ret = request_module("snd-soc-wm9712");
0088 if (ret)
0089 dev_err(&op->dev, "request_module returned: %d\n", ret);
0090
0091 pdata->codec_device = platform_device_alloc("wm9712-codec", -1);
0092 if (!pdata->codec_device)
0093 dev_err(&op->dev, "platform_device_alloc() failed\n");
0094
0095 ret = platform_device_add(pdata->codec_device);
0096 if (ret) {
0097 dev_err(&op->dev, "platform_device_add() failed: %d\n", ret);
0098 platform_device_put(pdata->codec_device);
0099 }
0100
0101 ret = snd_soc_register_card(card);
0102 if (ret) {
0103 dev_err(&op->dev, "snd_soc_register_card() failed: %d\n", ret);
0104 platform_device_unregister(pdata->codec_device);
0105 }
0106
0107 platform_set_drvdata(op, pdata);
0108 return ret;
0109
0110 }
0111
0112 static int pcm030_fabric_remove(struct platform_device *op)
0113 {
0114 struct pcm030_audio_data *pdata = platform_get_drvdata(op);
0115
0116 snd_soc_unregister_card(pdata->card);
0117 platform_device_unregister(pdata->codec_device);
0118
0119 return 0;
0120 }
0121
0122 static const struct of_device_id pcm030_audio_match[] = {
0123 { .compatible = "phytec,pcm030-audio-fabric", },
0124 {}
0125 };
0126 MODULE_DEVICE_TABLE(of, pcm030_audio_match);
0127
0128 static struct platform_driver pcm030_fabric_driver = {
0129 .probe = pcm030_fabric_probe,
0130 .remove = pcm030_fabric_remove,
0131 .driver = {
0132 .name = DRV_NAME,
0133 .of_match_table = pcm030_audio_match,
0134 },
0135 };
0136
0137 module_platform_driver(pcm030_fabric_driver);
0138
0139
0140 MODULE_AUTHOR("Jon Smirl <jonsmirl@gmail.com>");
0141 MODULE_DESCRIPTION(DRV_NAME ": mpc5200 pcm030 fabric driver");
0142 MODULE_LICENSE("GPL");
0143