bcb654c96996083f6258bf116064906620292a9b
[openwrt/staging/wigyori.git] /
1 From 9d9f0aa59569bf2aa826aea3a4a2d1ace3a155f4 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)
5 support (#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 ASoC: allo-piano-dac: fix S24_LE format
23
24 Remove set_bclk_ratio call so 24-bit data is transmitted in
25 24 bclk cycles.
26
27 Also remove hw_params and ops as they are no longer needed.
28
29 Signed-off-by: Matthias Reichl <hias@horus.com>
30
31 ASoC: allo-piano-dac: use modern dai_link style
32
33 Signed-off-by: Hui Wang <hui.wang@canonical.com>
34 ---
35 sound/soc/bcm/allo-piano-dac.c | 122 +++++++++++++++++++++++++++++++++
36 1 file changed, 122 insertions(+)
37 create mode 100644 sound/soc/bcm/allo-piano-dac.c
38
39 --- /dev/null
40 +++ b/sound/soc/bcm/allo-piano-dac.c
41 @@ -0,0 +1,122 @@
42 +/*
43 + * ALSA ASoC Machine Driver for Allo Piano DAC
44 + *
45 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
46 + * Copyright 2016
47 + * based on code by Daniel Matuschek <info@crazy-audio.com>
48 + * based on code by Florian Meier <florian.meier@koalo.de>
49 + *
50 + * This program is free software; you can redistribute it and/or
51 + * modify it under the terms of the GNU General Public License
52 + * version 2 as published by the Free Software Foundation.
53 + *
54 + * This program is distributed in the hope that it will be useful, but
55 + * WITHOUT ANY WARRANTY; without even the implied warranty of
56 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
57 + * General Public License for more details.
58 + */
59 +
60 +#include <linux/module.h>
61 +#include <linux/platform_device.h>
62 +
63 +#include <sound/core.h>
64 +#include <sound/pcm.h>
65 +#include <sound/pcm_params.h>
66 +#include <sound/soc.h>
67 +
68 +static bool digital_gain_0db_limit = true;
69 +
70 +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
71 +{
72 + if (digital_gain_0db_limit) {
73 + int ret;
74 + struct snd_soc_card *card = rtd->card;
75 +
76 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
77 + 207);
78 + if (ret < 0)
79 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
80 + ret);
81 + }
82 +
83 + return 0;
84 +}
85 +
86 +SND_SOC_DAILINK_DEFS(allo_piano_dai,
87 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
88 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi")),
89 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
90 +
91 +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
92 +{
93 + .name = "Piano DAC",
94 + .stream_name = "Piano DAC HiFi",
95 + .dai_fmt = SND_SOC_DAIFMT_I2S |
96 + SND_SOC_DAIFMT_NB_NF |
97 + SND_SOC_DAIFMT_CBS_CFS,
98 + .init = snd_allo_piano_dac_init,
99 + SND_SOC_DAILINK_REG(allo_piano_dai),
100 +},
101 +};
102 +
103 +/* audio machine driver */
104 +static struct snd_soc_card snd_allo_piano_dac = {
105 + .name = "PianoDAC",
106 + .owner = THIS_MODULE,
107 + .dai_link = snd_allo_piano_dac_dai,
108 + .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
109 +};
110 +
111 +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
112 +{
113 + int ret = 0;
114 +
115 + snd_allo_piano_dac.dev = &pdev->dev;
116 +
117 + if (pdev->dev.of_node) {
118 + struct device_node *i2s_node;
119 + struct snd_soc_dai_link *dai;
120 +
121 + dai = &snd_allo_piano_dac_dai[0];
122 + i2s_node = of_parse_phandle(pdev->dev.of_node,
123 + "i2s-controller", 0);
124 +
125 + if (i2s_node) {
126 + dai->cpus->dai_name = NULL;
127 + dai->cpus->of_node = i2s_node;
128 + dai->platforms->name = NULL;
129 + dai->platforms->of_node = i2s_node;
130 + }
131 +
132 + digital_gain_0db_limit = !of_property_read_bool(
133 + pdev->dev.of_node, "allo,24db_digital_gain");
134 + }
135 +
136 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_allo_piano_dac);
137 + if (ret && ret != -EPROBE_DEFER)
138 + dev_err(&pdev->dev,
139 + "snd_soc_register_card() failed: %d\n", ret);
140 +
141 + return ret;
142 +}
143 +
144 +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
145 + { .compatible = "allo,piano-dac", },
146 + { /* sentinel */ },
147 +};
148 +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
149 +
150 +static struct platform_driver snd_allo_piano_dac_driver = {
151 + .driver = {
152 + .name = "snd-allo-piano-dac",
153 + .owner = THIS_MODULE,
154 + .of_match_table = snd_allo_piano_dac_of_match,
155 + },
156 + .probe = snd_allo_piano_dac_probe,
157 +};
158 +
159 +module_platform_driver(snd_allo_piano_dac_driver);
160 +
161 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
162 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC");
163 +MODULE_LICENSE("GPL v2");