kernel: bump 4.14 to 4.14.93
[openwrt/staging/chunkeey.git] / target / linux / brcm2708 / patches-4.14 / 950-0064-ASoC-Add-support-for-HifiBerry-DAC.patch
1 From d8e006c632e99c1f7440673181104768135a64e4 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 064/454] 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 | 9 ++-
13 sound/soc/bcm/Makefile | 4 ++
14 sound/soc/bcm/hifiberry_dac.c | 124 ++++++++++++++++++++++++++++++++++
15 3 files changed, 136 insertions(+), 1 deletion(-)
16 create mode 100644 sound/soc/bcm/hifiberry_dac.c
17
18 --- a/sound/soc/bcm/Kconfig
19 +++ b/sound/soc/bcm/Kconfig
20 @@ -16,4 +16,11 @@ config SND_SOC_CYGNUS
21 Say Y if you want to add support for ASoC audio on Broadcom
22 Cygnus chips (bcm958300, bcm958305, bcm911360)
23
24 - If you don't know what to do here, say N.
25 \ No newline at end of file
26 + If you don't know what to do here, say N.
27 +
28 +config SND_BCM2708_SOC_HIFIBERRY_DAC
29 + tristate "Support for HifiBerry DAC"
30 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
31 + select SND_SOC_PCM5102A
32 + help
33 + Say Y or M if you want to add support for HifiBerry DAC.
34 --- a/sound/soc/bcm/Makefile
35 +++ b/sound/soc/bcm/Makefile
36 @@ -8,3 +8,7 @@ snd-soc-cygnus-objs := cygnus-pcm.o cygn
37
38 obj-$(CONFIG_SND_SOC_CYGNUS) += snd-soc-cygnus.o
39
40 +# BCM2708 Machine Support
41 +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
42 +
43 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
44 --- /dev/null
45 +++ b/sound/soc/bcm/hifiberry_dac.c
46 @@ -0,0 +1,124 @@
47 +/*
48 + * ASoC Driver for HifiBerry DAC
49 + *
50 + * Author: Florian Meier <florian.meier@koalo.de>
51 + * Copyright 2013
52 + *
53 + * This program is free software; you can redistribute it and/or
54 + * modify it under the terms of the GNU General Public License
55 + * version 2 as published by the Free Software Foundation.
56 + *
57 + * This program is distributed in the hope that it will be useful, but
58 + * WITHOUT ANY WARRANTY; without even the implied warranty of
59 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
60 + * General Public License for more details.
61 + */
62 +
63 +#include <linux/module.h>
64 +#include <linux/platform_device.h>
65 +
66 +#include <sound/core.h>
67 +#include <sound/pcm.h>
68 +#include <sound/pcm_params.h>
69 +#include <sound/soc.h>
70 +#include <sound/jack.h>
71 +
72 +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
73 +{
74 + return 0;
75 +}
76 +
77 +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
78 + struct snd_pcm_hw_params *params)
79 +{
80 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
81 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
82 +
83 + unsigned int sample_bits =
84 + snd_pcm_format_physical_width(params_format(params));
85 +
86 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
87 +}
88 +
89 +/* machine stream operations */
90 +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
91 + .hw_params = snd_rpi_hifiberry_dac_hw_params,
92 +};
93 +
94 +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
95 +{
96 + .name = "HifiBerry DAC",
97 + .stream_name = "HifiBerry DAC HiFi",
98 + .cpu_dai_name = "bcm2708-i2s.0",
99 + .codec_dai_name = "pcm5102a-hifi",
100 + .platform_name = "bcm2708-i2s.0",
101 + .codec_name = "pcm5102a-codec",
102 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
103 + SND_SOC_DAIFMT_CBS_CFS,
104 + .ops = &snd_rpi_hifiberry_dac_ops,
105 + .init = snd_rpi_hifiberry_dac_init,
106 +},
107 +};
108 +
109 +/* audio machine driver */
110 +static struct snd_soc_card snd_rpi_hifiberry_dac = {
111 + .name = "snd_rpi_hifiberry_dac",
112 + .driver_name = "HifiberryDac",
113 + .owner = THIS_MODULE,
114 + .dai_link = snd_rpi_hifiberry_dac_dai,
115 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
116 +};
117 +
118 +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
119 +{
120 + int ret = 0;
121 +
122 + snd_rpi_hifiberry_dac.dev = &pdev->dev;
123 +
124 + if (pdev->dev.of_node) {
125 + struct device_node *i2s_node;
126 + struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_dac_dai[0];
127 + i2s_node = of_parse_phandle(pdev->dev.of_node,
128 + "i2s-controller", 0);
129 +
130 + if (i2s_node) {
131 + dai->cpu_dai_name = NULL;
132 + dai->cpu_of_node = i2s_node;
133 + dai->platform_name = NULL;
134 + dai->platform_of_node = i2s_node;
135 + }
136 + }
137 +
138 + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
139 + if (ret && ret != -EPROBE_DEFER)
140 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
141 +
142 + return ret;
143 +}
144 +
145 +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
146 +{
147 + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
148 +}
149 +
150 +static const struct of_device_id snd_rpi_hifiberry_dac_of_match[] = {
151 + { .compatible = "hifiberry,hifiberry-dac", },
152 + {},
153 +};
154 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dac_of_match);
155 +
156 +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
157 + .driver = {
158 + .name = "snd-hifiberry-dac",
159 + .owner = THIS_MODULE,
160 + .of_match_table = snd_rpi_hifiberry_dac_of_match,
161 + },
162 + .probe = snd_rpi_hifiberry_dac_probe,
163 + .remove = snd_rpi_hifiberry_dac_remove,
164 +};
165 +
166 +module_platform_driver(snd_rpi_hifiberry_dac_driver);
167 +
168 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
169 +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
170 +MODULE_LICENSE("GPL v2");