brcm2708: update linux 4.4 patches to latest version
[openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0069-Add-IQaudIO-Sound-Card-support-for-Raspberry-Pi.patch
1 From 80fa31f923b4967bc86be20c5af780ef284fc972 Mon Sep 17 00:00:00 2001
2 From: Gordon Garrity <gordon@iqaudio.com>
3 Date: Sat, 8 Mar 2014 16:56:57 +0000
4 Subject: [PATCH 069/170] Add IQaudIO Sound Card support for Raspberry Pi
5
6 Set a limit of 0dB on Digital Volume Control
7
8 The main volume control in the PCM512x DAC has a range up to
9 +24dB. This is dangerously loud and can potentially cause massive
10 clipping in the output stages. Therefore this sets a sensible
11 limit of 0dB for this control.
12 ---
13  sound/soc/bcm/Kconfig       |   7 +++
14  sound/soc/bcm/Makefile      |   2 +
15  sound/soc/bcm/iqaudio-dac.c | 132 ++++++++++++++++++++++++++++++++++++++++++++
16  3 files changed, 141 insertions(+)
17  create mode 100644 sound/soc/bcm/iqaudio-dac.c
18
19 --- a/sound/soc/bcm/Kconfig
20 +++ b/sound/soc/bcm/Kconfig
21 @@ -28,3 +28,10 @@ config SND_BCM2708_SOC_RPI_DAC
22          select SND_SOC_PCM1794A
23          help
24           Say Y or M if you want to add support for RPi-DAC.
25 +
26 +config SND_BCM2708_SOC_IQAUDIO_DAC
27 +       tristate "Support for IQaudIO-DAC"
28 +       depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
29 +       select SND_SOC_PCM512x_I2C
30 +       help
31 +         Say Y or M if you want to add support for IQaudIO-DAC.
32 --- a/sound/soc/bcm/Makefile
33 +++ b/sound/soc/bcm/Makefile
34 @@ -7,7 +7,9 @@ obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd
35  snd-soc-hifiberry-dac-objs := hifiberry_dac.o
36  snd-soc-hifiberry-digi-objs := hifiberry_digi.o
37  snd-soc-rpi-dac-objs := rpi-dac.o
38 +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
39  
40  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
41  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
42  obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
43 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
44 --- /dev/null
45 +++ b/sound/soc/bcm/iqaudio-dac.c
46 @@ -0,0 +1,132 @@
47 +/*
48 + * ASoC Driver for IQaudIO DAC
49 + *
50 + * Author:     Florian Meier <florian.meier@koalo.de>
51 + *             Copyright 2013
52 + *
53 + * This program is free software; you can redistribute it and/or
54 + * modify it under the terms of the GNU General Public License
55 + * version 2 as published by the Free Software Foundation.
56 + *
57 + * This program is distributed in the hope that it will be useful, but
58 + * WITHOUT ANY WARRANTY; without even the implied warranty of
59 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
60 + * General Public License for more details.
61 + */
62 +
63 +#include <linux/module.h>
64 +#include <linux/platform_device.h>
65 +
66 +#include <sound/core.h>
67 +#include <sound/pcm.h>
68 +#include <sound/pcm_params.h>
69 +#include <sound/soc.h>
70 +#include <sound/jack.h>
71 +
72 +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
73 +{
74 +       int ret;
75 +       struct snd_soc_card *card = rtd->card;
76 +
77 +       ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
78 +       if (ret < 0)
79 +               dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
80 +
81 +       return 0;
82 +}
83 +
84 +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream,
85 +                                      struct snd_pcm_hw_params *params)
86 +{
87 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
88 +// NOT USED    struct snd_soc_dai *codec_dai = rtd->codec_dai;
89 +// NOT USED    struct snd_soc_codec *codec = rtd->codec;
90 +       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
91 +
92 +       unsigned int sample_bits =
93 +               snd_pcm_format_physical_width(params_format(params));
94 +
95 +       return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
96 +}
97 +
98 +/* machine stream operations */
99 +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = {
100 +       .hw_params = snd_rpi_iqaudio_dac_hw_params,
101 +};
102 +
103 +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
104 +{
105 +       .name           = "IQaudIO DAC",
106 +       .stream_name    = "IQaudIO DAC HiFi",
107 +       .cpu_dai_name   = "bcm2708-i2s.0",
108 +       .codec_dai_name = "pcm512x-hifi",
109 +       .platform_name  = "bcm2708-i2s.0",
110 +       .codec_name     = "pcm512x.1-004c",
111 +       .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
112 +                               SND_SOC_DAIFMT_CBS_CFS,
113 +       .ops            = &snd_rpi_iqaudio_dac_ops,
114 +       .init           = snd_rpi_iqaudio_dac_init,
115 +},
116 +};
117 +
118 +/* audio machine driver */
119 +static struct snd_soc_card snd_rpi_iqaudio_dac = {
120 +       .name         = "IQaudIODAC",
121 +       .dai_link     = snd_rpi_iqaudio_dac_dai,
122 +       .num_links    = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
123 +};
124 +
125 +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
126 +{
127 +       int ret = 0;
128 +
129 +       snd_rpi_iqaudio_dac.dev = &pdev->dev;
130 +
131 +       if (pdev->dev.of_node) {
132 +           struct device_node *i2s_node;
133 +           struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_dac_dai[0];
134 +           i2s_node = of_parse_phandle(pdev->dev.of_node,
135 +                                       "i2s-controller", 0);
136 +
137 +           if (i2s_node) {
138 +               dai->cpu_dai_name = NULL;
139 +               dai->cpu_of_node = i2s_node;
140 +               dai->platform_name = NULL;
141 +               dai->platform_of_node = i2s_node;
142 +           }
143 +       }
144 +
145 +       ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
146 +       if (ret)
147 +               dev_err(&pdev->dev,
148 +                       "snd_soc_register_card() failed: %d\n", ret);
149 +
150 +       return ret;
151 +}
152 +
153 +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
154 +{
155 +       return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
156 +}
157 +
158 +static const struct of_device_id iqaudio_of_match[] = {
159 +       { .compatible = "iqaudio,iqaudio-dac", },
160 +       {},
161 +};
162 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
163 +
164 +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
165 +       .driver = {
166 +               .name   = "snd-rpi-iqaudio-dac",
167 +               .owner  = THIS_MODULE,
168 +               .of_match_table = iqaudio_of_match,
169 +       },
170 +       .probe          = snd_rpi_iqaudio_dac_probe,
171 +       .remove         = snd_rpi_iqaudio_dac_remove,
172 +};
173 +
174 +module_platform_driver(snd_rpi_iqaudio_dac_driver);
175 +
176 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
177 +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
178 +MODULE_LICENSE("GPL v2");