brcm2708: add linux 4.1 support
[openwrt/svn-archive/archive.git] / target / linux / brcm2708 / patches-4.1 / 0061-Add-driver-for-rpi-proto.patch
1 From 9ea362cfd9b8e0b2a8896a713b8b82c0c5834a68 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 061/121] Add driver for rpi-proto
5
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.
9
10 URL to the audio chip:
11 http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/
12
13 Playback tested with devicetree enabled.
14
15 Signed-off-by: Waldemar Brodkorb <wbrodkorb@conet.de>
16 ---
17 sound/soc/bcm/Kconfig | 7 +++
18 sound/soc/bcm/Makefile | 2 +
19 sound/soc/bcm/rpi-proto.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++
20 3 files changed, 162 insertions(+)
21 create mode 100644 sound/soc/bcm/rpi-proto.c
22
23 --- a/sound/soc/bcm/Kconfig
24 +++ b/sound/soc/bcm/Kconfig
25 @@ -54,6 +54,13 @@ config SND_BCM2708_SOC_RPI_DAC
26 help
27 Say Y or M if you want to add support for RPi-DAC.
28
29 +config SND_BCM2708_SOC_RPI_PROTO
30 + tristate "Support for Rpi-PROTO"
31 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
32 + select SND_SOC_WM8731
33 + help
34 + Say Y or M if you want to add support for Audio Codec Board PROTO (WM8731).
35 +
36 config SND_BCM2708_SOC_IQAUDIO_DAC
37 tristate "Support for IQaudIO-DAC"
38 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
39 --- a/sound/soc/bcm/Makefile
40 +++ b/sound/soc/bcm/Makefile
41 @@ -14,6 +14,7 @@ snd-soc-hifiberry-dacplus-objs := hifibe
42 snd-soc-hifiberry-digi-objs := hifiberry_digi.o
43 snd-soc-hifiberry-amp-objs := hifiberry_amp.o
44 snd-soc-rpi-dac-objs := rpi-dac.o
45 +snd-soc-rpi-proto-objs := rpi-proto.o
46 snd-soc-iqaudio-dac-objs := iqaudio-dac.o
47
48 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
49 @@ -21,4 +22,5 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_D
50 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
51 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
52 obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
53 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
54 obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
55 --- /dev/null
56 +++ b/sound/soc/bcm/rpi-proto.c
57 @@ -0,0 +1,153 @@
58 +/*
59 + * ASoC driver for PROTO AudioCODEC (with a WM8731)
60 + * connected to a Raspberry Pi
61 + *
62 + * Author: Florian Meier, <koalo@koalo.de>
63 + * Copyright 2013
64 + *
65 + * This program is free software; you can redistribute it and/or modify
66 + * it under the terms of the GNU General Public License version 2 as
67 + * published by the Free Software Foundation.
68 + */
69 +
70 +#include <linux/module.h>
71 +#include <linux/platform_device.h>
72 +
73 +#include <sound/core.h>
74 +#include <sound/pcm.h>
75 +#include <sound/soc.h>
76 +#include <sound/jack.h>
77 +
78 +#include "../codecs/wm8731.h"
79 +
80 +static const unsigned int wm8731_rates_12288000[] = {
81 + 8000, 32000, 48000, 96000,
82 +};
83 +
84 +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
85 + .list = wm8731_rates_12288000,
86 + .count = ARRAY_SIZE(wm8731_rates_12288000),
87 +};
88 +
89 +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
90 +{
91 + /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
92 + snd_pcm_hw_constraint_list(substream->runtime, 0,
93 + SNDRV_PCM_HW_PARAM_RATE,
94 + &wm8731_constraints_12288000);
95 + return 0;
96 +}
97 +
98 +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
99 + struct snd_pcm_hw_params *params)
100 +{
101 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
102 + struct snd_soc_codec *codec = rtd->codec;
103 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
104 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
105 + int sysclk = 12288000; /* This is fixed on this board */
106 +
107 + /* Set proto bclk */
108 + int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
109 + if (ret < 0){
110 + dev_err(codec->dev,
111 + "Failed to set BCLK ratio %d\n", ret);
112 + return ret;
113 + }
114 +
115 + /* Set proto sysclk */
116 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
117 + sysclk, SND_SOC_CLOCK_IN);
118 + if (ret < 0) {
119 + dev_err(codec->dev,
120 + "Failed to set WM8731 SYSCLK: %d\n", ret);
121 + return ret;
122 + }
123 +
124 + return 0;
125 +}
126 +
127 +/* machine stream operations */
128 +static struct snd_soc_ops snd_rpi_proto_ops = {
129 + .startup = snd_rpi_proto_startup,
130 + .hw_params = snd_rpi_proto_hw_params,
131 +};
132 +
133 +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
134 +{
135 + .name = "WM8731",
136 + .stream_name = "WM8731 HiFi",
137 + .cpu_dai_name = "bcm2708-i2s.0",
138 + .codec_dai_name = "wm8731-hifi",
139 + .platform_name = "bcm2708-i2s.0",
140 + .codec_name = "wm8731.1-001a",
141 + .dai_fmt = SND_SOC_DAIFMT_I2S
142 + | SND_SOC_DAIFMT_NB_NF
143 + | SND_SOC_DAIFMT_CBM_CFM,
144 + .ops = &snd_rpi_proto_ops,
145 +},
146 +};
147 +
148 +/* audio machine driver */
149 +static struct snd_soc_card snd_rpi_proto = {
150 + .name = "snd_rpi_proto",
151 + .dai_link = snd_rpi_proto_dai,
152 + .num_links = ARRAY_SIZE(snd_rpi_proto_dai),
153 +};
154 +
155 +static int snd_rpi_proto_probe(struct platform_device *pdev)
156 +{
157 + int ret = 0;
158 +
159 + snd_rpi_proto.dev = &pdev->dev;
160 +
161 + if (pdev->dev.of_node) {
162 + struct device_node *i2s_node;
163 + struct snd_soc_dai_link *dai = &snd_rpi_proto_dai[0];
164 + i2s_node = of_parse_phandle(pdev->dev.of_node,
165 + "i2s-controller", 0);
166 +
167 + if (i2s_node) {
168 + dai->cpu_dai_name = NULL;
169 + dai->cpu_of_node = i2s_node;
170 + dai->platform_name = NULL;
171 + dai->platform_of_node = i2s_node;
172 + }
173 + }
174 +
175 + ret = snd_soc_register_card(&snd_rpi_proto);
176 + if (ret) {
177 + dev_err(&pdev->dev,
178 + "snd_soc_register_card() failed: %d\n", ret);
179 + }
180 +
181 + return ret;
182 +}
183 +
184 +
185 +static int snd_rpi_proto_remove(struct platform_device *pdev)
186 +{
187 + return snd_soc_unregister_card(&snd_rpi_proto);
188 +}
189 +
190 +static const struct of_device_id snd_rpi_proto_of_match[] = {
191 + { .compatible = "rpi,rpi-proto", },
192 + {},
193 +};
194 +MODULE_DEVICE_TABLE(of, snd_rpi_proto_of_match);
195 +
196 +static struct platform_driver snd_rpi_proto_driver = {
197 + .driver = {
198 + .name = "snd-rpi-proto",
199 + .owner = THIS_MODULE,
200 + .of_match_table = snd_rpi_proto_of_match,
201 + },
202 + .probe = snd_rpi_proto_probe,
203 + .remove = snd_rpi_proto_remove,
204 +};
205 +
206 +module_platform_driver(snd_rpi_proto_driver);
207 +
208 +MODULE_AUTHOR("Florian Meier");
209 +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
210 +MODULE_LICENSE("GPL");