brcm2708: update 4.1 patches
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.1 / 0044-Add-IQaudIO-Sound-Card-support-for-Raspberry-Pi.patch
1 From f8fb55caae97e04ab68a955eb8946dbee37cd6fe 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 044/222] 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 arch/arm/mach-bcm2708/bcm2708.c | 21 ++++++++
14 sound/soc/bcm/Kconfig | 7 +++
15 sound/soc/bcm/Makefile | 2 +
16 sound/soc/bcm/iqaudio-dac.c | 117 ++++++++++++++++++++++++++++++++++++++++
17 4 files changed, 147 insertions(+)
18 create mode 100644 sound/soc/bcm/iqaudio-dac.c
19
20 --- a/arch/arm/mach-bcm2708/bcm2708.c
21 +++ b/arch/arm/mach-bcm2708/bcm2708.c
22 @@ -681,6 +681,22 @@ static struct platform_device snd_pcm179
23 };
24 #endif
25
26 +
27 +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
28 +static struct platform_device snd_rpi_iqaudio_dac_device = {
29 + .name = "snd-rpi-iqaudio-dac",
30 + .id = 0,
31 + .num_resources = 0,
32 +};
33 +
34 +// Use the actual device name rather than generic driver name
35 +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
36 + {
37 + I2C_BOARD_INFO("pcm5122", 0x4c)
38 + },
39 +};
40 +#endif
41 +
42 int __init bcm_register_device(struct platform_device *pdev)
43 {
44 int ret;
45 @@ -864,6 +880,11 @@ void __init bcm2708_init(void)
46 bcm_register_device_dt(&snd_pcm1794a_codec_device);
47 #endif
48
49 +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
50 + bcm_register_device_dt(&snd_rpi_iqaudio_dac_device);
51 + i2c_register_board_info_dt(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
52 +#endif
53 +
54 if (!use_dt) {
55 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
56 struct amba_device *d = amba_devs[i];
57 --- a/sound/soc/bcm/Kconfig
58 +++ b/sound/soc/bcm/Kconfig
59 @@ -39,3 +39,10 @@ config SND_BCM2708_SOC_RPI_DAC
60 select SND_SOC_PCM1794A
61 help
62 Say Y or M if you want to add support for RPi-DAC.
63 +
64 +config SND_BCM2708_SOC_IQAUDIO_DAC
65 + tristate "Support for IQaudIO-DAC"
66 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
67 + select SND_SOC_PCM512x_I2C
68 + help
69 + Say Y or M if you want to add support for IQaudIO-DAC.
70 --- a/sound/soc/bcm/Makefile
71 +++ b/sound/soc/bcm/Makefile
72 @@ -12,7 +12,9 @@ obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd
73 snd-soc-hifiberry-dac-objs := hifiberry_dac.o
74 snd-soc-hifiberry-digi-objs := hifiberry_digi.o
75 snd-soc-rpi-dac-objs := rpi-dac.o
76 +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
77
78 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
79 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
80 obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
81 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
82 --- /dev/null
83 +++ b/sound/soc/bcm/iqaudio-dac.c
84 @@ -0,0 +1,117 @@
85 +/*
86 + * ASoC Driver for IQaudIO DAC
87 + *
88 + * Author: Florian Meier <florian.meier@koalo.de>
89 + * Copyright 2013
90 + *
91 + * This program is free software; you can redistribute it and/or
92 + * modify it under the terms of the GNU General Public License
93 + * version 2 as published by the Free Software Foundation.
94 + *
95 + * This program is distributed in the hope that it will be useful, but
96 + * WITHOUT ANY WARRANTY; without even the implied warranty of
97 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
98 + * General Public License for more details.
99 + */
100 +
101 +#include <linux/module.h>
102 +#include <linux/platform_device.h>
103 +
104 +#include <sound/core.h>
105 +#include <sound/pcm.h>
106 +#include <sound/pcm_params.h>
107 +#include <sound/soc.h>
108 +#include <sound/jack.h>
109 +
110 +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
111 +{
112 + int ret;
113 + struct snd_soc_card *card = rtd->card;
114 + struct snd_soc_codec *codec = rtd->codec;
115 +
116 + ret = snd_soc_limit_volume(codec, "Digital Playback Volume", 207);
117 + if (ret < 0)
118 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
119 +
120 + return 0;
121 +}
122 +
123 +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream,
124 + struct snd_pcm_hw_params *params)
125 +{
126 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
127 +// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai;
128 +// NOT USED struct snd_soc_codec *codec = rtd->codec;
129 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
130 +
131 + unsigned int sample_bits =
132 + snd_pcm_format_physical_width(params_format(params));
133 +
134 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
135 +}
136 +
137 +/* machine stream operations */
138 +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = {
139 + .hw_params = snd_rpi_iqaudio_dac_hw_params,
140 +};
141 +
142 +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
143 +{
144 + .name = "IQaudIO DAC",
145 + .stream_name = "IQaudIO DAC HiFi",
146 + .cpu_dai_name = "bcm2708-i2s.0",
147 + .codec_dai_name = "pcm512x-hifi",
148 + .platform_name = "bcm2708-i2s.0",
149 + .codec_name = "pcm512x.1-004c",
150 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
151 + SND_SOC_DAIFMT_CBS_CFS,
152 + .ops = &snd_rpi_iqaudio_dac_ops,
153 + .init = snd_rpi_iqaudio_dac_init,
154 +},
155 +};
156 +
157 +/* audio machine driver */
158 +static struct snd_soc_card snd_rpi_iqaudio_dac = {
159 + .name = "IQaudIODAC",
160 + .dai_link = snd_rpi_iqaudio_dac_dai,
161 + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
162 +};
163 +
164 +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
165 +{
166 + int ret = 0;
167 +
168 + snd_rpi_iqaudio_dac.dev = &pdev->dev;
169 + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
170 + if (ret)
171 + dev_err(&pdev->dev,
172 + "snd_soc_register_card() failed: %d\n", ret);
173 +
174 + return ret;
175 +}
176 +
177 +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
178 +{
179 + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
180 +}
181 +
182 +static const struct of_device_id iqaudio_of_match[] = {
183 + { .compatible = "iqaudio,iqaudio-dac", },
184 + {},
185 +};
186 +
187 +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
188 + .driver = {
189 + .name = "snd-rpi-iqaudio-dac",
190 + .owner = THIS_MODULE,
191 + .of_match_table = iqaudio_of_match,
192 + },
193 + .probe = snd_rpi_iqaudio_dac_probe,
194 + .remove = snd_rpi_iqaudio_dac_remove,
195 +};
196 +
197 +module_platform_driver(snd_rpi_iqaudio_dac_driver);
198 +
199 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
200 +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
201 +MODULE_LICENSE("GPL v2");