firmware-utils: bump to git HEAD
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0064-Add-Support-for-JustBoom-Audio-boards.patch
1 From 752d2f2029aa9b3710e9fef40757d834899e3ff1 Mon Sep 17 00:00:00 2001
2 From: Aaron Shaw <shawaj@gmail.com>
3 Date: Thu, 7 Apr 2016 21:26:21 +0100
4 Subject: [PATCH] Add Support for JustBoom Audio boards
5
6 justboom-dac: Adjust for ALSA API change
7
8 As of 4.4, snd_soc_limit_volume now takes a struct snd_soc_card *
9 rather than a struct snd_soc_codec *.
10
11 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
12
13 ASoC: justboom-dac: fix S24_LE format
14
15 Remove set_bclk_ratio call so 24-bit data is transmitted in
16 24 bclk cycles.
17
18 Also remove hw_params as it's no longer needed.
19
20 Signed-off-by: Matthias Reichl <hias@horus.com>
21
22 ASoC: justboom-dac: use modern dai_link style
23
24 Signed-off-by: Matthias Reichl <hias@horus.com>
25 ---
26 sound/soc/bcm/justboom-dac.c | 147 +++++++++++++++++++++++++++++++++++
27 1 file changed, 147 insertions(+)
28 create mode 100644 sound/soc/bcm/justboom-dac.c
29
30 --- /dev/null
31 +++ b/sound/soc/bcm/justboom-dac.c
32 @@ -0,0 +1,147 @@
33 +/*
34 + * ASoC Driver for JustBoom DAC Raspberry Pi HAT Sound Card
35 + *
36 + * Author: Milan Neskovic
37 + * Copyright 2016
38 + * based on code by Daniel Matuschek <info@crazy-audio.com>
39 + * based on code by Florian Meier <florian.meier@koalo.de>
40 + *
41 + * This program is free software; you can redistribute it and/or
42 + * modify it under the terms of the GNU General Public License
43 + * version 2 as published by the Free Software Foundation.
44 + *
45 + * This program is distributed in the hope that it will be useful, but
46 + * WITHOUT ANY WARRANTY; without even the implied warranty of
47 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
48 + * General Public License for more details.
49 + */
50 +
51 +#include <linux/module.h>
52 +#include <linux/platform_device.h>
53 +
54 +#include <sound/core.h>
55 +#include <sound/pcm.h>
56 +#include <sound/pcm_params.h>
57 +#include <sound/soc.h>
58 +#include <sound/jack.h>
59 +
60 +#include "../codecs/pcm512x.h"
61 +
62 +static bool digital_gain_0db_limit = true;
63 +
64 +static int snd_rpi_justboom_dac_init(struct snd_soc_pcm_runtime *rtd)
65 +{
66 + struct snd_soc_component *component = rtd->codec_dai->component;
67 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
68 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
69 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
70 +
71 + if (digital_gain_0db_limit)
72 + {
73 + int ret;
74 + struct snd_soc_card *card = rtd->card;
75 +
76 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
77 + if (ret < 0)
78 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
79 + }
80 +
81 + return 0;
82 +}
83 +
84 +static int snd_rpi_justboom_dac_startup(struct snd_pcm_substream *substream) {
85 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
86 + struct snd_soc_component *component = rtd->codec_dai->component;
87 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
88 + return 0;
89 +}
90 +
91 +static void snd_rpi_justboom_dac_shutdown(struct snd_pcm_substream *substream) {
92 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
93 + struct snd_soc_component *component = rtd->codec_dai->component;
94 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
95 +}
96 +
97 +/* machine stream operations */
98 +static struct snd_soc_ops snd_rpi_justboom_dac_ops = {
99 + .startup = snd_rpi_justboom_dac_startup,
100 + .shutdown = snd_rpi_justboom_dac_shutdown,
101 +};
102 +
103 +SND_SOC_DAILINK_DEFS(hifi,
104 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
105 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
106 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
107 +
108 +static struct snd_soc_dai_link snd_rpi_justboom_dac_dai[] = {
109 +{
110 + .name = "JustBoom DAC",
111 + .stream_name = "JustBoom DAC HiFi",
112 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
113 + SND_SOC_DAIFMT_CBS_CFS,
114 + .ops = &snd_rpi_justboom_dac_ops,
115 + .init = snd_rpi_justboom_dac_init,
116 + SND_SOC_DAILINK_REG(hifi),
117 +},
118 +};
119 +
120 +/* audio machine driver */
121 +static struct snd_soc_card snd_rpi_justboom_dac = {
122 + .name = "snd_rpi_justboom_dac",
123 + .driver_name = "JustBoomDac",
124 + .owner = THIS_MODULE,
125 + .dai_link = snd_rpi_justboom_dac_dai,
126 + .num_links = ARRAY_SIZE(snd_rpi_justboom_dac_dai),
127 +};
128 +
129 +static int snd_rpi_justboom_dac_probe(struct platform_device *pdev)
130 +{
131 + int ret = 0;
132 +
133 + snd_rpi_justboom_dac.dev = &pdev->dev;
134 +
135 + if (pdev->dev.of_node) {
136 + struct device_node *i2s_node;
137 + struct snd_soc_dai_link *dai = &snd_rpi_justboom_dac_dai[0];
138 + i2s_node = of_parse_phandle(pdev->dev.of_node,
139 + "i2s-controller", 0);
140 +
141 + if (i2s_node) {
142 + dai->cpus->dai_name = NULL;
143 + dai->cpus->of_node = i2s_node;
144 + dai->platforms->name = NULL;
145 + dai->platforms->of_node = i2s_node;
146 + }
147 +
148 + digital_gain_0db_limit = !of_property_read_bool(
149 + pdev->dev.of_node, "justboom,24db_digital_gain");
150 + }
151 +
152 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_justboom_dac);
153 + if (ret && ret != -EPROBE_DEFER)
154 + dev_err(&pdev->dev,
155 + "snd_soc_register_card() failed: %d\n", ret);
156 +
157 + return ret;
158 +}
159 +
160 +static const struct of_device_id snd_rpi_justboom_dac_of_match[] = {
161 + { .compatible = "justboom,justboom-dac", },
162 + {},
163 +};
164 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_dac_of_match);
165 +
166 +static struct platform_driver snd_rpi_justboom_dac_driver = {
167 + .driver = {
168 + .name = "snd-rpi-justboom-dac",
169 + .owner = THIS_MODULE,
170 + .of_match_table = snd_rpi_justboom_dac_of_match,
171 + },
172 + .probe = snd_rpi_justboom_dac_probe,
173 +};
174 +
175 +module_platform_driver(snd_rpi_justboom_dac_driver);
176 +
177 +MODULE_AUTHOR("Milan Neskovic <info@justboom.co>");
178 +MODULE_DESCRIPTION("ASoC Driver for JustBoom PI DAC HAT Sound Card");
179 +MODULE_LICENSE("GPL v2");