64e785d2a6a38a14f92a7d352cead2cd0e9e8113
[openwrt/openwrt.git] /
1 From 779409817cf1af2c38055af64c11e026cb0bb4e9 Mon Sep 17 00:00:00 2001
2 From: Clive Messer <clive.m.messer@gmail.com>
3 Date: Mon, 19 Sep 2016 14:01:04 +0100
4 Subject: [PATCH] Allo Piano DAC boards: Initial 2 channel (stereo) support
5 (#1645)
6
7 Add initial 2 channel (stereo) support for Allo Piano DAC (2.0/2.1) boards,
8 using allo-piano-dac-pcm512x-audio overlay and allo-piano-dac ALSA ASoC
9 machine driver.
10
11 NB. The initial support is 2 channel (stereo) ONLY!
12 (The Piano DAC 2.1 will only support 2 channel (stereo) left/right output,
13 pending an update to the upstream pcm512x codec driver, which will have
14 to be submitted via upstream. With the initial downstream support,
15 provided by this patch, the Piano DAC 2.1 subwoofer outputs will
16 not function.)
17
18 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
19 Signed-off-by: Clive Messer <clive.messer@digitaldreamtime.co.uk>
20 Tested-by: Clive Messer <clive.messer@digitaldreamtime.co.uk>
21 ---
22 sound/soc/bcm/Kconfig | 7 ++
23 sound/soc/bcm/Makefile | 2 +
24 sound/soc/bcm/allo-piano-dac.c | 144 +++++++++++++++++++++++++++++++++++++++++
25 3 files changed, 153 insertions(+)
26 create mode 100644 sound/soc/bcm/allo-piano-dac.c
27
28 --- a/sound/soc/bcm/Kconfig
29 +++ b/sound/soc/bcm/Kconfig
30 @@ -123,3 +123,10 @@ config SND_BCM2708_SOC_DIONAUDIO_LOCO
31 select SND_SOC_PCM5102a
32 help
33 Say Y or M if you want to add support for Dion Audio LOCO.
34 +
35 +config SND_BCM2708_SOC_ALLO_PIANO_DAC
36 + tristate "Support for Allo Piano DAC"
37 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
38 + select SND_SOC_PCM512x_I2C
39 + help
40 + Say Y or M if you want to add support for Allo Piano DAC.
41 --- a/sound/soc/bcm/Makefile
42 +++ b/sound/soc/bcm/Makefile
43 @@ -24,6 +24,7 @@ snd-soc-raspidac3-objs := raspidac3.o
44 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
45 snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
46 snd-soc-dionaudio-loco-objs := dionaudio_loco.o
47 +snd-soc-allo-piano-dac-objs := allo-piano-dac.o
48
49 obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
50 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
51 @@ -40,3 +41,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3)
52 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
53 obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
54 obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
55 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
56 --- /dev/null
57 +++ b/sound/soc/bcm/allo-piano-dac.c
58 @@ -0,0 +1,144 @@
59 +/*
60 + * ALSA ASoC Machine Driver for Allo Piano DAC
61 + *
62 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
63 + * Copyright 2016
64 + * based on code by Daniel Matuschek <info@crazy-audio.com>
65 + * based on code by Florian Meier <florian.meier@koalo.de>
66 + *
67 + * This program is free software; you can redistribute it and/or
68 + * modify it under the terms of the GNU General Public License
69 + * version 2 as published by the Free Software Foundation.
70 + *
71 + * This program is distributed in the hope that it will be useful, but
72 + * WITHOUT ANY WARRANTY; without even the implied warranty of
73 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74 + * General Public License for more details.
75 + */
76 +
77 +#include <linux/module.h>
78 +#include <linux/platform_device.h>
79 +
80 +#include <sound/core.h>
81 +#include <sound/pcm.h>
82 +#include <sound/pcm_params.h>
83 +#include <sound/soc.h>
84 +
85 +static bool digital_gain_0db_limit = true;
86 +
87 +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
88 +{
89 + if (digital_gain_0db_limit) {
90 + int ret;
91 + struct snd_soc_card *card = rtd->card;
92 +
93 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
94 + 207);
95 + if (ret < 0)
96 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
97 + ret);
98 + }
99 +
100 + return 0;
101 +}
102 +
103 +static int snd_allo_piano_dac_hw_params(
104 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
105 +{
106 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
107 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
108 +
109 + unsigned int sample_bits =
110 + snd_pcm_format_physical_width(params_format(params));
111 +
112 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
113 +}
114 +
115 +/* machine stream operations */
116 +static struct snd_soc_ops snd_allo_piano_dac_ops = {
117 + .hw_params = snd_allo_piano_dac_hw_params,
118 +};
119 +
120 +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
121 +{
122 + .name = "Piano DAC",
123 + .stream_name = "Piano DAC HiFi",
124 + .cpu_dai_name = "bcm2708-i2s.0",
125 + .codec_dai_name = "pcm512x-hifi",
126 + .platform_name = "bcm2708-i2s.0",
127 + .codec_name = "pcm512x.1-004c",
128 + .dai_fmt = SND_SOC_DAIFMT_I2S |
129 + SND_SOC_DAIFMT_NB_NF |
130 + SND_SOC_DAIFMT_CBS_CFS,
131 + .ops = &snd_allo_piano_dac_ops,
132 + .init = snd_allo_piano_dac_init,
133 +},
134 +};
135 +
136 +/* audio machine driver */
137 +static struct snd_soc_card snd_allo_piano_dac = {
138 + .name = "PianoDAC",
139 + .owner = THIS_MODULE,
140 + .dai_link = snd_allo_piano_dac_dai,
141 + .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
142 +};
143 +
144 +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
145 +{
146 + int ret = 0;
147 +
148 + snd_allo_piano_dac.dev = &pdev->dev;
149 +
150 + if (pdev->dev.of_node) {
151 + struct device_node *i2s_node;
152 + struct snd_soc_dai_link *dai;
153 +
154 + dai = &snd_allo_piano_dac_dai[0];
155 + i2s_node = of_parse_phandle(pdev->dev.of_node,
156 + "i2s-controller", 0);
157 +
158 + if (i2s_node) {
159 + dai->cpu_dai_name = NULL;
160 + dai->cpu_of_node = i2s_node;
161 + dai->platform_name = NULL;
162 + dai->platform_of_node = i2s_node;
163 + }
164 +
165 + digital_gain_0db_limit = !of_property_read_bool(
166 + pdev->dev.of_node, "allo,24db_digital_gain");
167 + }
168 +
169 + ret = snd_soc_register_card(&snd_allo_piano_dac);
170 + if (ret)
171 + dev_err(&pdev->dev,
172 + "snd_soc_register_card() failed: %d\n", ret);
173 +
174 + return ret;
175 +}
176 +
177 +static int snd_allo_piano_dac_remove(struct platform_device *pdev)
178 +{
179 + return snd_soc_unregister_card(&snd_allo_piano_dac);
180 +}
181 +
182 +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
183 + { .compatible = "allo,piano-dac", },
184 + { /* sentinel */ },
185 +};
186 +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
187 +
188 +static struct platform_driver snd_allo_piano_dac_driver = {
189 + .driver = {
190 + .name = "snd-allo-piano-dac",
191 + .owner = THIS_MODULE,
192 + .of_match_table = snd_allo_piano_dac_of_match,
193 + },
194 + .probe = snd_allo_piano_dac_probe,
195 + .remove = snd_allo_piano_dac_remove,
196 +};
197 +
198 +module_platform_driver(snd_allo_piano_dac_driver);
199 +
200 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
201 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC");
202 +MODULE_LICENSE("GPL v2");