brcm2708: add linux 4.19 support
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.19 / 950-0071-Add-Support-for-JustBoom-Audio-boards.patch
1 From 71cd216db9c7c05f05c8dd7c7afdfb24f718be74 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 071/703] 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 sound/soc/bcm/justboom-dac.c | 145 +++++++++++++++++++++++++++++++++++
23 1 file changed, 145 insertions(+)
24 create mode 100644 sound/soc/bcm/justboom-dac.c
25
26 --- /dev/null
27 +++ b/sound/soc/bcm/justboom-dac.c
28 @@ -0,0 +1,145 @@
29 +/*
30 + * ASoC Driver for JustBoom DAC Raspberry Pi HAT Sound Card
31 + *
32 + * Author: Milan Neskovic
33 + * Copyright 2016
34 + * based on code by Daniel Matuschek <info@crazy-audio.com>
35 + * based on code by Florian Meier <florian.meier@koalo.de>
36 + *
37 + * This program is free software; you can redistribute it and/or
38 + * modify it under the terms of the GNU General Public License
39 + * version 2 as published by the Free Software Foundation.
40 + *
41 + * This program is distributed in the hope that it will be useful, but
42 + * WITHOUT ANY WARRANTY; without even the implied warranty of
43 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44 + * General Public License for more details.
45 + */
46 +
47 +#include <linux/module.h>
48 +#include <linux/platform_device.h>
49 +
50 +#include <sound/core.h>
51 +#include <sound/pcm.h>
52 +#include <sound/pcm_params.h>
53 +#include <sound/soc.h>
54 +#include <sound/jack.h>
55 +
56 +#include "../codecs/pcm512x.h"
57 +
58 +static bool digital_gain_0db_limit = true;
59 +
60 +static int snd_rpi_justboom_dac_init(struct snd_soc_pcm_runtime *rtd)
61 +{
62 + struct snd_soc_component *component = rtd->codec_dai->component;
63 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
64 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
65 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
66 +
67 + if (digital_gain_0db_limit)
68 + {
69 + int ret;
70 + struct snd_soc_card *card = rtd->card;
71 +
72 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
73 + if (ret < 0)
74 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
75 + }
76 +
77 + return 0;
78 +}
79 +
80 +static int snd_rpi_justboom_dac_startup(struct snd_pcm_substream *substream) {
81 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
82 + struct snd_soc_component *component = rtd->codec_dai->component;
83 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
84 + return 0;
85 +}
86 +
87 +static void snd_rpi_justboom_dac_shutdown(struct snd_pcm_substream *substream) {
88 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
89 + struct snd_soc_component *component = rtd->codec_dai->component;
90 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
91 +}
92 +
93 +/* machine stream operations */
94 +static struct snd_soc_ops snd_rpi_justboom_dac_ops = {
95 + .startup = snd_rpi_justboom_dac_startup,
96 + .shutdown = snd_rpi_justboom_dac_shutdown,
97 +};
98 +
99 +static struct snd_soc_dai_link snd_rpi_justboom_dac_dai[] = {
100 +{
101 + .name = "JustBoom DAC",
102 + .stream_name = "JustBoom DAC HiFi",
103 + .cpu_dai_name = "bcm2708-i2s.0",
104 + .codec_dai_name = "pcm512x-hifi",
105 + .platform_name = "bcm2708-i2s.0",
106 + .codec_name = "pcm512x.1-004d",
107 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
108 + SND_SOC_DAIFMT_CBS_CFS,
109 + .ops = &snd_rpi_justboom_dac_ops,
110 + .init = snd_rpi_justboom_dac_init,
111 +},
112 +};
113 +
114 +/* audio machine driver */
115 +static struct snd_soc_card snd_rpi_justboom_dac = {
116 + .name = "snd_rpi_justboom_dac",
117 + .driver_name = "JustBoomDac",
118 + .owner = THIS_MODULE,
119 + .dai_link = snd_rpi_justboom_dac_dai,
120 + .num_links = ARRAY_SIZE(snd_rpi_justboom_dac_dai),
121 +};
122 +
123 +static int snd_rpi_justboom_dac_probe(struct platform_device *pdev)
124 +{
125 + int ret = 0;
126 +
127 + snd_rpi_justboom_dac.dev = &pdev->dev;
128 +
129 + if (pdev->dev.of_node) {
130 + struct device_node *i2s_node;
131 + struct snd_soc_dai_link *dai = &snd_rpi_justboom_dac_dai[0];
132 + i2s_node = of_parse_phandle(pdev->dev.of_node,
133 + "i2s-controller", 0);
134 +
135 + if (i2s_node) {
136 + dai->cpu_dai_name = NULL;
137 + dai->cpu_of_node = i2s_node;
138 + dai->platform_name = NULL;
139 + dai->platform_of_node = i2s_node;
140 + }
141 +
142 + digital_gain_0db_limit = !of_property_read_bool(
143 + pdev->dev.of_node, "justboom,24db_digital_gain");
144 + }
145 +
146 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_justboom_dac);
147 + if (ret && ret != -EPROBE_DEFER)
148 + dev_err(&pdev->dev,
149 + "snd_soc_register_card() failed: %d\n", ret);
150 +
151 + return ret;
152 +}
153 +
154 +static const struct of_device_id snd_rpi_justboom_dac_of_match[] = {
155 + { .compatible = "justboom,justboom-dac", },
156 + {},
157 +};
158 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_dac_of_match);
159 +
160 +static struct platform_driver snd_rpi_justboom_dac_driver = {
161 + .driver = {
162 + .name = "snd-rpi-justboom-dac",
163 + .owner = THIS_MODULE,
164 + .of_match_table = snd_rpi_justboom_dac_of_match,
165 + },
166 + .probe = snd_rpi_justboom_dac_probe,
167 +};
168 +
169 +module_platform_driver(snd_rpi_justboom_dac_driver);
170 +
171 +MODULE_AUTHOR("Milan Neskovic <info@justboom.co>");
172 +MODULE_DESCRIPTION("ASoC Driver for JustBoom PI DAC HAT Sound Card");
173 +MODULE_LICENSE("GPL v2");