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