2 * ASoC driver for PROTO AudioCODEC (with a WM8731)
4 * Author: Florian Meier, <koalo@koalo.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
15 #include <sound/core.h>
16 #include <sound/pcm.h>
17 #include <sound/soc.h>
18 #include <sound/jack.h>
20 #include "../codecs/wm8731.h"
22 #define XTAL_RATE 12288000 /* This is fixed on this board */
24 static int snd_proto_init(struct snd_soc_pcm_runtime *rtd)
26 struct snd_soc_card *card = rtd->card;
27 struct snd_soc_dai *codec_dai = rtd->codec_dai;
29 /* Set proto sysclk */
30 int ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
31 XTAL_RATE, SND_SOC_CLOCK_IN);
33 dev_err(card->dev, "Failed to set WM8731 SYSCLK: %d\n",
41 static const struct snd_soc_dapm_widget snd_proto_widget[] = {
42 SND_SOC_DAPM_MIC("Microphone Jack", NULL),
43 SND_SOC_DAPM_HP("Headphone Jack", NULL),
46 static const struct snd_soc_dapm_route snd_proto_route[] = {
47 /* speaker connected to LHPOUT/RHPOUT */
48 {"Headphone Jack", NULL, "LHPOUT"},
49 {"Headphone Jack", NULL, "RHPOUT"},
51 /* mic is connected to Mic Jack, with WM8731 Mic Bias */
52 {"MICIN", NULL, "Mic Bias"},
53 {"Mic Bias", NULL, "Microphone Jack"},
56 /* audio machine driver */
57 static struct snd_soc_card snd_proto = {
58 .name = "snd_mikroe_proto",
60 .dapm_widgets = snd_proto_widget,
61 .num_dapm_widgets = ARRAY_SIZE(snd_proto_widget),
62 .dapm_routes = snd_proto_route,
63 .num_dapm_routes = ARRAY_SIZE(snd_proto_route),
66 static int snd_proto_probe(struct platform_device *pdev)
68 struct snd_soc_dai_link *dai;
69 struct device_node *np = pdev->dev.of_node;
70 struct device_node *codec_np, *cpu_np;
71 struct device_node *bitclkmaster = NULL;
72 struct device_node *framemaster = NULL;
77 dev_err(&pdev->dev, "No device node supplied\n");
81 snd_proto.dev = &pdev->dev;
82 ret = snd_soc_of_parse_card_name(&snd_proto, "model");
86 dai = devm_kzalloc(&pdev->dev, sizeof(*dai), GFP_KERNEL);
90 snd_proto.dai_link = dai;
91 snd_proto.num_links = 1;
94 dai->stream_name = "WM8731 HiFi";
95 dai->codec_dai_name = "wm8731-hifi";
96 dai->init = &snd_proto_init;
98 codec_np = of_parse_phandle(np, "audio-codec", 0);
100 dev_err(&pdev->dev, "audio-codec node missing\n");
103 dai->codec_of_node = codec_np;
105 cpu_np = of_parse_phandle(np, "i2s-controller", 0);
107 dev_err(&pdev->dev, "i2s-controller missing\n");
110 dai->cpu_of_node = cpu_np;
111 dai->platform_of_node = cpu_np;
113 dai_fmt = snd_soc_of_parse_daifmt(np, NULL,
114 &bitclkmaster, &framemaster);
115 if (bitclkmaster != framemaster) {
116 dev_err(&pdev->dev, "Must be the same bitclock and frame master\n");
120 dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
121 if (codec_np == bitclkmaster)
122 dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
124 dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
126 of_node_put(bitclkmaster);
127 of_node_put(framemaster);
128 dai->dai_fmt = dai_fmt;
130 of_node_put(codec_np);
133 ret = snd_soc_register_card(&snd_proto);
134 if (ret && ret != -EPROBE_DEFER)
136 "snd_soc_register_card() failed: %d\n", ret);
141 static int snd_proto_remove(struct platform_device *pdev)
143 return snd_soc_unregister_card(&snd_proto);
146 static const struct of_device_id snd_proto_of_match[] = {
147 { .compatible = "mikroe,mikroe-proto", },
150 MODULE_DEVICE_TABLE(of, snd_proto_of_match);
152 static struct platform_driver snd_proto_driver = {
154 .name = "snd-mikroe-proto",
155 .of_match_table = snd_proto_of_match,
157 .probe = snd_proto_probe,
158 .remove = snd_proto_remove,
161 module_platform_driver(snd_proto_driver);
163 MODULE_AUTHOR("Florian Meier");
164 MODULE_DESCRIPTION("ASoC Driver for PROTO board (WM8731)");
165 MODULE_LICENSE("GPL");