1 From ba93efdc28c5e66d5d01a1cd35c458aa1074d7d5 Mon Sep 17 00:00:00 2001
2 From: Florian Meier <florian.meier@koalo.de>
3 Date: Fri, 22 Nov 2013 19:19:08 +0100
4 Subject: [PATCH 120/196] ASoC: Add support for HifiBerry DAC
6 This adds a machine driver for the HifiBerry DAC.
7 It is a sound card that can
8 be stacked onto the Raspberry Pi.
10 Signed-off-by: Florian Meier <florian.meier@koalo.de>
12 sound/soc/bcm/Kconfig | 7 +++
13 sound/soc/bcm/Makefile | 5 +++
14 sound/soc/bcm/hifiberry_dac.c | 100 ++++++++++++++++++++++++++++++++++++++++++
15 3 files changed, 112 insertions(+)
16 create mode 100644 sound/soc/bcm/hifiberry_dac.c
18 diff --git a/sound/soc/bcm/Kconfig b/sound/soc/bcm/Kconfig
19 index 37c8f8c..8b14e37 100644
20 --- a/sound/soc/bcm/Kconfig
21 +++ b/sound/soc/bcm/Kconfig
22 @@ -8,3 +8,10 @@ config SND_BCM2708_SOC_I2S
23 Say Y or M if you want to add support for codecs attached to
24 the BCM2708 I2S interface. You will also need
25 to select the audio interfaces to support below.
27 +config SND_BCM2708_SOC_HIFIBERRY_DAC
28 + tristate "Support for HifiBerry DAC"
29 + depends on SND_BCM2708_SOC_I2S
30 + select SND_SOC_PCM5102A
32 + Say Y or M if you want to add support for HifiBerry DAC.
33 diff --git a/sound/soc/bcm/Makefile b/sound/soc/bcm/Makefile
34 index 486ea09..6834b4d 100644
35 --- a/sound/soc/bcm/Makefile
36 +++ b/sound/soc/bcm/Makefile
38 snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
40 obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
42 +# BCM2708 Machine Support
43 +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
45 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
46 diff --git a/sound/soc/bcm/hifiberry_dac.c b/sound/soc/bcm/hifiberry_dac.c
48 index 0000000..4b70b45
50 +++ b/sound/soc/bcm/hifiberry_dac.c
53 + * ASoC Driver for HifiBerry DAC
55 + * Author: Florian Meier <florian.meier@koalo.de>
58 + * This program is free software; you can redistribute it and/or
59 + * modify it under the terms of the GNU General Public License
60 + * version 2 as published by the Free Software Foundation.
62 + * This program is distributed in the hope that it will be useful, but
63 + * WITHOUT ANY WARRANTY; without even the implied warranty of
64 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
65 + * General Public License for more details.
68 +#include <linux/module.h>
69 +#include <linux/platform_device.h>
71 +#include <sound/core.h>
72 +#include <sound/pcm.h>
73 +#include <sound/pcm_params.h>
74 +#include <sound/soc.h>
75 +#include <sound/jack.h>
77 +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
82 +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
83 + struct snd_pcm_hw_params *params)
85 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
86 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
88 + unsigned int sample_bits =
89 + snd_pcm_format_physical_width(params_format(params));
91 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
94 +/* machine stream operations */
95 +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
96 + .hw_params = snd_rpi_hifiberry_dac_hw_params,
99 +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
101 + .name = "HifiBerry DAC",
102 + .stream_name = "HifiBerry DAC HiFi",
103 + .cpu_dai_name = "bcm2708-i2s.0",
104 + .codec_dai_name = "pcm5102a-hifi",
105 + .platform_name = "bcm2708-i2s.0",
106 + .codec_name = "pcm5102a-codec",
107 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
108 + SND_SOC_DAIFMT_CBS_CFS,
109 + .ops = &snd_rpi_hifiberry_dac_ops,
110 + .init = snd_rpi_hifiberry_dac_init,
114 +/* audio machine driver */
115 +static struct snd_soc_card snd_rpi_hifiberry_dac = {
116 + .name = "snd_rpi_hifiberry_dac",
117 + .dai_link = snd_rpi_hifiberry_dac_dai,
118 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
121 +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
125 + snd_rpi_hifiberry_dac.dev = &pdev->dev;
126 + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
128 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
133 +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
135 + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
138 +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
140 + .name = "snd-hifiberry-dac",
141 + .owner = THIS_MODULE,
143 + .probe = snd_rpi_hifiberry_dac_probe,
144 + .remove = snd_rpi_hifiberry_dac_remove,
147 +module_platform_driver(snd_rpi_hifiberry_dac_driver);
149 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
150 +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
151 +MODULE_LICENSE("GPL v2");