brcm2708: switch to linux 4.4 and update patches
[openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0085-RaspiDAC3-support.patch
1 From 305847dcc80fa3e3ffccd0e6c77b45d0a54ed185 Mon Sep 17 00:00:00 2001
2 From: Jan Grulich <jan@grulich.eu>
3 Date: Mon, 24 Aug 2015 16:03:47 +0100
4 Subject: [PATCH 085/156] RaspiDAC3 support
5
6 Signed-off-by: Jan Grulich <jan@grulich.eu>
7
8 config: fix RaspiDAC Rev.3x dependencies
9
10 Change depends to SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
11 like the other I2S soundcard drivers.
12
13 Signed-off-by: Matthias Reichl <hias@horus.com>
14 ---
15  sound/soc/bcm/Kconfig     |   8 ++
16  sound/soc/bcm/Makefile    |   2 +
17  sound/soc/bcm/raspidac3.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++
18  3 files changed, 201 insertions(+)
19  create mode 100644 sound/soc/bcm/raspidac3.c
20
21 --- a/sound/soc/bcm/Kconfig
22 +++ b/sound/soc/bcm/Kconfig
23 @@ -56,3 +56,11 @@ config SND_BCM2708_SOC_IQAUDIO_DAC
24         select SND_SOC_PCM512x_I2C
25         help
26           Say Y or M if you want to add support for IQaudIO-DAC.
27 +
28 +config SND_BCM2708_SOC_RASPIDAC3
29 +       tristate "Support for RaspiDAC Rev.3x"
30 +       depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
31 +       select SND_SOC_PCM512x_I2C
32 +       select SND_SOC_TPA6130A2
33 +       help
34 +         Say Y or M if you want to add support for RaspiDAC Rev.3x.
35 --- a/sound/soc/bcm/Makefile
36 +++ b/sound/soc/bcm/Makefile
37 @@ -11,6 +11,7 @@ snd-soc-hifiberry-amp-objs := hifiberry_
38  snd-soc-rpi-dac-objs := rpi-dac.o
39  snd-soc-rpi-proto-objs := rpi-proto.o
40  snd-soc-iqaudio-dac-objs := iqaudio-dac.o
41 +snd-soc-raspidac3-objs := raspidac3.o
42  
43  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
44  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
45 @@ -19,3 +20,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_A
46  obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
47  obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
48  obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
49 +obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
50 --- /dev/null
51 +++ b/sound/soc/bcm/raspidac3.c
52 @@ -0,0 +1,191 @@
53 +/*
54 + * ASoC Driver for RaspiDAC v3
55 + *
56 + * Author:     Jan Grulich <jan@grulich.eu>
57 + *             Copyright 2015
58 + *              based on code by Daniel Matuschek <daniel@hifiberry.com>
59 + *             based on code by Florian Meier <florian.meier@koalo.de>
60 + *
61 + * This program is free software; you can redistribute it and/or
62 + * modify it under the terms of the GNU General Public License
63 + * version 2 as published by the Free Software Foundation.
64 + *
65 + * This program is distributed in the hope that it will be useful, but
66 + * WITHOUT ANY WARRANTY; without even the implied warranty of
67 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
68 + * General Public License for more details.
69 + */
70 +
71 +#include <linux/module.h>
72 +#include <linux/platform_device.h>
73 +
74 +#include <sound/core.h>
75 +#include <sound/pcm.h>
76 +#include <sound/pcm_params.h>
77 +#include <sound/soc.h>
78 +#include <sound/jack.h>
79 +#include <sound/soc-dapm.h>
80 +
81 +#include "../codecs/pcm512x.h"
82 +#include "../codecs/tpa6130a2.h"
83 +
84 +/* sound card init */
85 +static int snd_rpi_raspidac3_init(struct snd_soc_pcm_runtime *rtd)
86 +{
87 +       int ret;
88 +       struct snd_soc_card *card = rtd->card;
89 +       struct snd_soc_codec *codec = rtd->codec;
90 +       snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
91 +       snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
92 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
93 +
94 +       ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
95 +       if (ret < 0)
96 +               dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
97 +       else {
98 +               struct snd_kcontrol *kctl;
99 +
100 +               ret = tpa6130a2_add_controls(codec);
101 +               if (ret < 0)
102 +                       dev_warn(card->dev, "Failed to add TPA6130A2 controls: %d\n",
103 +                                ret);
104 +               ret = snd_soc_limit_volume(card,
105 +                                          "TPA6130A2 Headphone Playback Volume",
106 +                                          54);
107 +               if (ret < 0)
108 +                       dev_warn(card->dev, "Failed to set TPA6130A2 volume limit: %d\n",
109 +                                ret);
110 +               kctl = snd_soc_card_get_kcontrol(card,
111 +                                                "TPA6130A2 Headphone Playback Volume");
112 +               if (kctl) {
113 +                       strcpy(kctl->id.name, "Headphones Playback Volume");
114 +                       /* disable the volume dB scale so alsamixer works */
115 +                       kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
116 +               }
117 +
118 +               kctl = snd_soc_card_get_kcontrol(card,
119 +                                                "TPA6130A2 Headphone Playback Switch");
120 +               if (kctl)
121 +                       strcpy(kctl->id.name, "Headphones Playback Switch");
122 +       }
123 +
124 +       return 0;
125 +}
126 +
127 +/* set hw parameters */
128 +static int snd_rpi_raspidac3_hw_params(struct snd_pcm_substream *substream,
129 +                                      struct snd_pcm_hw_params *params)
130 +{
131 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
132 +       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
133 +
134 +       unsigned int sample_bits =
135 +               snd_pcm_format_physical_width(params_format(params));
136 +
137 +       return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
138 +}
139 +
140 +/* startup */
141 +static int snd_rpi_raspidac3_startup(struct snd_pcm_substream *substream) {
142 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
143 +       struct snd_soc_codec *codec = rtd->codec;
144 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
145 +       tpa6130a2_stereo_enable(codec, 1);
146 +       return 0;
147 +}
148 +
149 +/* shutdown */
150 +static void snd_rpi_raspidac3_shutdown(struct snd_pcm_substream *substream) {
151 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
152 +       struct snd_soc_codec *codec = rtd->codec;
153 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
154 +       tpa6130a2_stereo_enable(codec, 0);
155 +}
156 +
157 +/* machine stream operations */
158 +static struct snd_soc_ops snd_rpi_raspidac3_ops = {
159 +       .hw_params = snd_rpi_raspidac3_hw_params,
160 +       .startup = snd_rpi_raspidac3_startup,
161 +       .shutdown = snd_rpi_raspidac3_shutdown,
162 +};
163 +
164 +/* interface setup */
165 +static struct snd_soc_dai_link snd_rpi_raspidac3_dai[] = {
166 +{
167 +       .name           = "RaspiDAC Rev.3x",
168 +       .stream_name    = "RaspiDAC HiFi",
169 +       .cpu_dai_name   = "bcm2708-i2s.0",
170 +       .codec_dai_name = "pcm512x-hifi",
171 +       .platform_name  = "bcm2708-i2s.0",
172 +       .codec_name     = "pcm512x.1-004c",
173 +       .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
174 +                               SND_SOC_DAIFMT_CBS_CFS,
175 +       .ops            = &snd_rpi_raspidac3_ops,
176 +       .init           = snd_rpi_raspidac3_init,
177 +},
178 +};
179 +
180 +/* audio machine driver */
181 +static struct snd_soc_card snd_rpi_raspidac3 = {
182 +       .name         = "RaspiDAC Rev.3x HiFi Audio Card",
183 +       .dai_link     = snd_rpi_raspidac3_dai,
184 +       .num_links    = ARRAY_SIZE(snd_rpi_raspidac3_dai),
185 +};
186 +
187 +/* sound card test */
188 +static int snd_rpi_raspidac3_probe(struct platform_device *pdev)
189 +{
190 +       int ret = 0;
191 +
192 +       snd_rpi_raspidac3.dev = &pdev->dev;
193 +
194 +       if (pdev->dev.of_node) {
195 +           struct device_node *i2s_node;
196 +           struct snd_soc_dai_link *dai = &snd_rpi_raspidac3_dai[0];
197 +           i2s_node = of_parse_phandle(pdev->dev.of_node,
198 +                                       "i2s-controller", 0);
199 +
200 +           if (i2s_node) {
201 +               dai->cpu_dai_name = NULL;
202 +               dai->cpu_of_node = i2s_node;
203 +               dai->platform_name = NULL;
204 +               dai->platform_of_node = i2s_node;
205 +           }
206 +       }
207 +
208 +       ret = snd_soc_register_card(&snd_rpi_raspidac3);
209 +       if (ret)
210 +               dev_err(&pdev->dev,
211 +                       "snd_soc_register_card() failed: %d\n", ret);
212 +
213 +       return ret;
214 +}
215 +
216 +/* sound card disconnect */
217 +static int snd_rpi_raspidac3_remove(struct platform_device *pdev)
218 +{
219 +       return snd_soc_unregister_card(&snd_rpi_raspidac3);
220 +}
221 +
222 +static const struct of_device_id raspidac3_of_match[] = {
223 +       { .compatible = "jg,raspidacv3", },
224 +       {},
225 +};
226 +MODULE_DEVICE_TABLE(of, raspidac3_of_match);
227 +
228 +/* sound card platform driver */
229 +static struct platform_driver snd_rpi_raspidac3_driver = {
230 +       .driver = {
231 +               .name   = "snd-rpi-raspidac3",
232 +               .owner  = THIS_MODULE,
233 +               .of_match_table = raspidac3_of_match,
234 +       },
235 +       .probe          = snd_rpi_raspidac3_probe,
236 +       .remove         = snd_rpi_raspidac3_remove,
237 +};
238 +
239 +module_platform_driver(snd_rpi_raspidac3_driver);
240 +
241 +MODULE_AUTHOR("Jan Grulich <jan@grulich.eu>");
242 +MODULE_DESCRIPTION("ASoC Driver for RaspiDAC Rev.3x");
243 +MODULE_LICENSE("GPL v2");