1 From 592ac515f17d49627b6653375267bad5c4bb1e5c 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] 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 | 4 ++
14 sound/soc/bcm/hifiberry_dac.c | 122 ++++++++++++++++++++++++++++++++++++++++++
15 3 files changed, 133 insertions(+)
16 create mode 100644 sound/soc/bcm/hifiberry_dac.c
18 --- a/sound/soc/bcm/Kconfig
19 +++ b/sound/soc/bcm/Kconfig
20 @@ -7,3 +7,10 @@ config SND_BCM2835_SOC_I2S
21 Say Y or M if you want to add support for codecs attached to
22 the BCM2835 I2S interface. You will also need
23 to select the audio interfaces to support below.
25 +config SND_BCM2708_SOC_HIFIBERRY_DAC
26 + tristate "Support for HifiBerry DAC"
27 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
28 + select SND_SOC_PCM5102A
30 + Say Y or M if you want to add support for HifiBerry DAC.
31 --- a/sound/soc/bcm/Makefile
32 +++ b/sound/soc/bcm/Makefile
33 @@ -3,3 +3,7 @@ snd-soc-bcm2835-i2s-objs := bcm2835-i2s.
35 obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd-soc-bcm2835-i2s.o
37 +# BCM2708 Machine Support
38 +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
40 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
42 +++ b/sound/soc/bcm/hifiberry_dac.c
45 + * ASoC Driver for HifiBerry DAC
47 + * Author: Florian Meier <florian.meier@koalo.de>
50 + * This program is free software; you can redistribute it and/or
51 + * modify it under the terms of the GNU General Public License
52 + * version 2 as published by the Free Software Foundation.
54 + * This program is distributed in the hope that it will be useful, but
55 + * WITHOUT ANY WARRANTY; without even the implied warranty of
56 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
57 + * General Public License for more details.
60 +#include <linux/module.h>
61 +#include <linux/platform_device.h>
63 +#include <sound/core.h>
64 +#include <sound/pcm.h>
65 +#include <sound/pcm_params.h>
66 +#include <sound/soc.h>
67 +#include <sound/jack.h>
69 +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
74 +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
75 + struct snd_pcm_hw_params *params)
77 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
78 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
80 + unsigned int sample_bits =
81 + snd_pcm_format_physical_width(params_format(params));
83 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
86 +/* machine stream operations */
87 +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
88 + .hw_params = snd_rpi_hifiberry_dac_hw_params,
91 +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
93 + .name = "HifiBerry DAC",
94 + .stream_name = "HifiBerry DAC HiFi",
95 + .cpu_dai_name = "bcm2708-i2s.0",
96 + .codec_dai_name = "pcm5102a-hifi",
97 + .platform_name = "bcm2708-i2s.0",
98 + .codec_name = "pcm5102a-codec",
99 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
100 + SND_SOC_DAIFMT_CBS_CFS,
101 + .ops = &snd_rpi_hifiberry_dac_ops,
102 + .init = snd_rpi_hifiberry_dac_init,
106 +/* audio machine driver */
107 +static struct snd_soc_card snd_rpi_hifiberry_dac = {
108 + .name = "snd_rpi_hifiberry_dac",
109 + .dai_link = snd_rpi_hifiberry_dac_dai,
110 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
113 +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
117 + snd_rpi_hifiberry_dac.dev = &pdev->dev;
119 + if (pdev->dev.of_node) {
120 + struct device_node *i2s_node;
121 + struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_dac_dai[0];
122 + i2s_node = of_parse_phandle(pdev->dev.of_node,
123 + "i2s-controller", 0);
126 + dai->cpu_dai_name = NULL;
127 + dai->cpu_of_node = i2s_node;
128 + dai->platform_name = NULL;
129 + dai->platform_of_node = i2s_node;
133 + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
135 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
140 +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
142 + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
145 +static const struct of_device_id snd_rpi_hifiberry_dac_of_match[] = {
146 + { .compatible = "hifiberry,hifiberry-dac", },
149 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dac_of_match);
151 +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
153 + .name = "snd-hifiberry-dac",
154 + .owner = THIS_MODULE,
155 + .of_match_table = snd_rpi_hifiberry_dac_of_match,
157 + .probe = snd_rpi_hifiberry_dac_probe,
158 + .remove = snd_rpi_hifiberry_dac_remove,
161 +module_platform_driver(snd_rpi_hifiberry_dac_driver);
163 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
164 +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
165 +MODULE_LICENSE("GPL v2");