brcm2708: update linux 4.4 patches to latest version
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0063-ASoC-Add-support-for-HifiBerry-DAC.patch
1 From 9cf0b8eed930ac26384249e193c1c91044a460e1 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
5
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.
9
10 Signed-off-by: Florian Meier <florian.meier@koalo.de>
11 ---
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
17
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.
24 +
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
29 + help
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.
34
35 obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd-soc-bcm2835-i2s.o
36
37 +# BCM2708 Machine Support
38 +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
39 +
40 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
41 --- /dev/null
42 +++ b/sound/soc/bcm/hifiberry_dac.c
43 @@ -0,0 +1,122 @@
44 +/*
45 + * ASoC Driver for HifiBerry DAC
46 + *
47 + * Author: Florian Meier <florian.meier@koalo.de>
48 + * Copyright 2013
49 + *
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.
53 + *
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.
58 + */
59 +
60 +#include <linux/module.h>
61 +#include <linux/platform_device.h>
62 +
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>
68 +
69 +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
70 +{
71 + return 0;
72 +}
73 +
74 +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
75 + struct snd_pcm_hw_params *params)
76 +{
77 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
78 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
79 +
80 + unsigned int sample_bits =
81 + snd_pcm_format_physical_width(params_format(params));
82 +
83 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
84 +}
85 +
86 +/* machine stream operations */
87 +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
88 + .hw_params = snd_rpi_hifiberry_dac_hw_params,
89 +};
90 +
91 +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
92 +{
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,
103 +},
104 +};
105 +
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),
111 +};
112 +
113 +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
114 +{
115 + int ret = 0;
116 +
117 + snd_rpi_hifiberry_dac.dev = &pdev->dev;
118 +
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);
124 +
125 + if (i2s_node) {
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;
130 + }
131 + }
132 +
133 + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
134 + if (ret)
135 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
136 +
137 + return ret;
138 +}
139 +
140 +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
141 +{
142 + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
143 +}
144 +
145 +static const struct of_device_id snd_rpi_hifiberry_dac_of_match[] = {
146 + { .compatible = "hifiberry,hifiberry-dac", },
147 + {},
148 +};
149 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dac_of_match);
150 +
151 +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
152 + .driver = {
153 + .name = "snd-hifiberry-dac",
154 + .owner = THIS_MODULE,
155 + .of_match_table = snd_rpi_hifiberry_dac_of_match,
156 + },
157 + .probe = snd_rpi_hifiberry_dac_probe,
158 + .remove = snd_rpi_hifiberry_dac_remove,
159 +};
160 +
161 +module_platform_driver(snd_rpi_hifiberry_dac_driver);
162 +
163 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
164 +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
165 +MODULE_LICENSE("GPL v2");