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
6 Set a limit of 0dB on Digital Volume Control
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.
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
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
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",
34 +// Use the actual device name rather than generic driver name
35 +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
37 + I2C_BOARD_INFO("pcm5122", 0x4c)
42 int __init bcm_register_device(struct platform_device *pdev)
45 @@ -864,6 +880,11 @@ void __init bcm2708_init(void)
46 bcm_register_device_dt(&snd_pcm1794a_codec_device);
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));
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
62 Say Y or M if you want to add support for RPi-DAC.
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
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
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
83 +++ b/sound/soc/bcm/iqaudio-dac.c
86 + * ASoC Driver for IQaudIO DAC
88 + * Author: Florian Meier <florian.meier@koalo.de>
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.
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.
101 +#include <linux/module.h>
102 +#include <linux/platform_device.h>
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>
110 +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
113 + struct snd_soc_card *card = rtd->card;
114 + struct snd_soc_codec *codec = rtd->codec;
116 + ret = snd_soc_limit_volume(codec, "Digital Playback Volume", 207);
118 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
123 +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream,
124 + struct snd_pcm_hw_params *params)
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;
131 + unsigned int sample_bits =
132 + snd_pcm_format_physical_width(params_format(params));
134 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
137 +/* machine stream operations */
138 +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = {
139 + .hw_params = snd_rpi_iqaudio_dac_hw_params,
142 +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
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,
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),
164 +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
168 + snd_rpi_iqaudio_dac.dev = &pdev->dev;
169 + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
171 + dev_err(&pdev->dev,
172 + "snd_soc_register_card() failed: %d\n", ret);
177 +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
179 + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
182 +static const struct of_device_id iqaudio_of_match[] = {
183 + { .compatible = "iqaudio,iqaudio-dac", },
187 +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
189 + .name = "snd-rpi-iqaudio-dac",
190 + .owner = THIS_MODULE,
191 + .of_match_table = iqaudio_of_match,
193 + .probe = snd_rpi_iqaudio_dac_probe,
194 + .remove = snd_rpi_iqaudio_dac_remove,
197 +module_platform_driver(snd_rpi_iqaudio_dac_driver);
199 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
200 +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
201 +MODULE_LICENSE("GPL v2");