1 From b3cf65c5d12ff3bd52843a35dc912a705371d5b6 Mon Sep 17 00:00:00 2001
2 From: Waldemar Brodkorb <wbrodkorb@conet.de>
3 Date: Wed, 25 Mar 2015 09:26:17 +0100
4 Subject: [PATCH] Add driver for rpi-proto
6 Forward port of 3.10.x driver from https://github.com/koalo
7 We are using a custom board and would like to use rpi 3.18.x
8 kernel. Patch works fine for our embedded system.
10 URL to the audio chip:
11 http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/
13 Playback tested with devicetree enabled.
15 Signed-off-by: Waldemar Brodkorb <wbrodkorb@conet.de>
17 ASoC: rpi-proto: use modern dai_link style
19 Signed-off-by: Hui Wang <hui.wang@canonical.com>
21 sound/soc/bcm/rpi-proto.c | 147 ++++++++++++++++++++++++++++++++++++++
22 1 file changed, 147 insertions(+)
23 create mode 100644 sound/soc/bcm/rpi-proto.c
26 +++ b/sound/soc/bcm/rpi-proto.c
29 + * ASoC driver for PROTO AudioCODEC (with a WM8731)
30 + * connected to a Raspberry Pi
32 + * Author: Florian Meier, <koalo@koalo.de>
35 + * This program is free software; you can redistribute it and/or modify
36 + * it under the terms of the GNU General Public License version 2 as
37 + * published by the Free Software Foundation.
40 +#include <linux/module.h>
41 +#include <linux/platform_device.h>
43 +#include <sound/core.h>
44 +#include <sound/pcm.h>
45 +#include <sound/soc.h>
46 +#include <sound/jack.h>
48 +#include "../codecs/wm8731.h"
50 +static const unsigned int wm8731_rates_12288000[] = {
51 + 8000, 32000, 48000, 96000,
54 +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
55 + .list = wm8731_rates_12288000,
56 + .count = ARRAY_SIZE(wm8731_rates_12288000),
59 +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
61 + /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
62 + snd_pcm_hw_constraint_list(substream->runtime, 0,
63 + SNDRV_PCM_HW_PARAM_RATE,
64 + &wm8731_constraints_12288000);
68 +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
69 + struct snd_pcm_hw_params *params)
71 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
72 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
73 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
74 + int sysclk = 12288000; /* This is fixed on this board */
76 + /* Set proto bclk */
77 + int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
79 + dev_err(rtd->card->dev,
80 + "Failed to set BCLK ratio %d\n", ret);
84 + /* Set proto sysclk */
85 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
86 + sysclk, SND_SOC_CLOCK_IN);
88 + dev_err(rtd->card->dev,
89 + "Failed to set WM8731 SYSCLK: %d\n", ret);
96 +/* machine stream operations */
97 +static struct snd_soc_ops snd_rpi_proto_ops = {
98 + .startup = snd_rpi_proto_startup,
99 + .hw_params = snd_rpi_proto_hw_params,
102 +SND_SOC_DAILINK_DEFS(rpi_proto,
103 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
104 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8731.1-001a", "wm8731-hifi")),
105 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
107 +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
110 + .stream_name = "WM8731 HiFi",
111 + .dai_fmt = SND_SOC_DAIFMT_I2S
112 + | SND_SOC_DAIFMT_NB_NF
113 + | SND_SOC_DAIFMT_CBM_CFM,
114 + .ops = &snd_rpi_proto_ops,
115 + SND_SOC_DAILINK_REG(rpi_proto),
119 +/* audio machine driver */
120 +static struct snd_soc_card snd_rpi_proto = {
121 + .name = "snd_rpi_proto",
122 + .owner = THIS_MODULE,
123 + .dai_link = snd_rpi_proto_dai,
124 + .num_links = ARRAY_SIZE(snd_rpi_proto_dai),
127 +static int snd_rpi_proto_probe(struct platform_device *pdev)
131 + snd_rpi_proto.dev = &pdev->dev;
133 + if (pdev->dev.of_node) {
134 + struct device_node *i2s_node;
135 + struct snd_soc_dai_link *dai = &snd_rpi_proto_dai[0];
136 + i2s_node = of_parse_phandle(pdev->dev.of_node,
137 + "i2s-controller", 0);
140 + dai->cpus->dai_name = NULL;
141 + dai->cpus->of_node = i2s_node;
142 + dai->platforms->name = NULL;
143 + dai->platforms->of_node = i2s_node;
147 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_proto);
148 + if (ret && ret != -EPROBE_DEFER)
149 + dev_err(&pdev->dev,
150 + "snd_soc_register_card() failed: %d\n", ret);
155 +static const struct of_device_id snd_rpi_proto_of_match[] = {
156 + { .compatible = "rpi,rpi-proto", },
159 +MODULE_DEVICE_TABLE(of, snd_rpi_proto_of_match);
161 +static struct platform_driver snd_rpi_proto_driver = {
163 + .name = "snd-rpi-proto",
164 + .owner = THIS_MODULE,
165 + .of_match_table = snd_rpi_proto_of_match,
167 + .probe = snd_rpi_proto_probe,
170 +module_platform_driver(snd_rpi_proto_driver);
172 +MODULE_AUTHOR("Florian Meier");
173 +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
174 +MODULE_LICENSE("GPL");