418788959af6bdbe61ffc5598e694d72444e45d6
[openwrt/staging/wigyori.git] / target / linux / brcm2708 / patches-4.19 / 950-0080-sound-Support-for-Dion-Audio-LOCO-V2-DAC-AMP-HAT.patch
1 From 261e3e2577768d848277489e26759f3f37b25aae Mon Sep 17 00:00:00 2001
2 From: Miquel <miquelblauw@hotmail.com>
3 Date: Fri, 24 Feb 2017 20:51:06 +0100
4 Subject: [PATCH 080/725] sound: Support for Dion Audio LOCO-V2 DAC-AMP HAT
5
6 Signed-off-by: Miquel Blauw <info@dionaudio.nl>
7
8 ASoC: dionaudio_loco-v2: fix S24_LE format
9
10 Remove set_bclk_ratio call so 24-bit data is transmitted in
11 24 bclk cycles.
12
13 Also remove hw_params and ops as they are no longer needed.
14
15 Signed-off-by: Matthias Reichl <hias@horus.com>
16 ---
17 sound/soc/bcm/dionaudio_loco-v2.c | 115 ++++++++++++++++++++++++++++++
18 1 file changed, 115 insertions(+)
19 create mode 100644 sound/soc/bcm/dionaudio_loco-v2.c
20
21 --- /dev/null
22 +++ b/sound/soc/bcm/dionaudio_loco-v2.c
23 @@ -0,0 +1,115 @@
24 +/*
25 + * ASoC Driver for Dion Audio LOCO-V2 DAC-AMP
26 + *
27 + * Author: Miquel Blauw <info@dionaudio.nl>
28 + * Copyright 2017
29 + *
30 + * Based on the software of the RPi-DAC writen by Florian Meier
31 + *
32 + * This program is free software; you can redistribute it and/or
33 + * modify it under the terms of the GNU General Public License
34 + * version 2 as published by the Free Software Foundation.
35 + *
36 + * This program is distributed in the hope that it will be useful, but
37 + * WITHOUT ANY WARRANTY; without even the implied warranty of
38 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 + * General Public License for more details.
40 + */
41 +
42 +#include <linux/module.h>
43 +#include <linux/platform_device.h>
44 +
45 +#include <sound/core.h>
46 +#include <sound/pcm.h>
47 +#include <sound/pcm_params.h>
48 +#include <sound/soc.h>
49 +#include <sound/jack.h>
50 +
51 +static bool digital_gain_0db_limit = true;
52 +
53 +static int snd_rpi_dionaudio_loco_v2_init(struct snd_soc_pcm_runtime *rtd)
54 +{
55 + if (digital_gain_0db_limit) {
56 + int ret;
57 + struct snd_soc_card *card = rtd->card;
58 +
59 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
60 + if (ret < 0)
61 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
62 + }
63 +
64 + return 0;
65 +}
66 +
67 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_v2_dai[] = {
68 +{
69 + .name = "DionAudio LOCO-V2",
70 + .stream_name = "DionAudio LOCO-V2 DAC-AMP",
71 + .cpu_dai_name = "bcm2708-i2s.0",
72 + .codec_dai_name = "pcm512x-hifi",
73 + .platform_name = "bcm2708-i2s.0",
74 + .codec_name = "pcm512x.1-004d",
75 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
76 + SND_SOC_DAIFMT_CBS_CFS,
77 + .init = snd_rpi_dionaudio_loco_v2_init,
78 +},};
79 +
80 +/* audio machine driver */
81 +static struct snd_soc_card snd_rpi_dionaudio_loco_v2 = {
82 + .name = "Dion Audio LOCO-V2",
83 + .dai_link = snd_rpi_dionaudio_loco_v2_dai,
84 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_v2_dai),
85 +};
86 +
87 +static int snd_rpi_dionaudio_loco_v2_probe(struct platform_device *pdev)
88 +{
89 + int ret = 0;
90 +
91 + snd_rpi_dionaudio_loco_v2.dev = &pdev->dev;
92 +
93 + if (pdev->dev.of_node) {
94 + struct device_node *i2s_node;
95 + struct snd_soc_dai_link *dai =
96 + &snd_rpi_dionaudio_loco_v2_dai[0];
97 +
98 + i2s_node = of_parse_phandle(pdev->dev.of_node,
99 + "i2s-controller", 0);
100 + if (i2s_node) {
101 + dai->cpu_dai_name = NULL;
102 + dai->cpu_of_node = i2s_node;
103 + dai->platform_name = NULL;
104 + dai->platform_of_node = i2s_node;
105 + }
106 +
107 + digital_gain_0db_limit = !of_property_read_bool(
108 + pdev->dev.of_node, "dionaudio,24db_digital_gain");
109 + }
110 +
111 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_dionaudio_loco_v2);
112 + if (ret)
113 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
114 + ret);
115 +
116 + return ret;
117 +}
118 +
119 +static const struct of_device_id dionaudio_of_match[] = {
120 + { .compatible = "dionaudio,dionaudio-loco-v2", },
121 + {},
122 +};
123 +MODULE_DEVICE_TABLE(of, dionaudio_of_match);
124 +
125 +static struct platform_driver snd_rpi_dionaudio_loco_v2_driver = {
126 + .driver = {
127 + .name = "snd-rpi-dionaudio-loco-v2",
128 + .owner = THIS_MODULE,
129 + .of_match_table = dionaudio_of_match,
130 + },
131 + .probe = snd_rpi_dionaudio_loco_v2_probe,
132 +};
133 +
134 +module_platform_driver(snd_rpi_dionaudio_loco_v2_driver);
135 +
136 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
137 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO-V2");
138 +MODULE_LICENSE("GPL v2");