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
6 justboom-dac: Adjust for ALSA API change
8 As of 4.4, snd_soc_limit_volume now takes a struct snd_soc_card *
9 rather than a struct snd_soc_codec *.
11 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
13 ASoC: justboom-dac: fix S24_LE format
15 Remove set_bclk_ratio call so 24-bit data is transmitted in
18 Also remove hw_params as it's no longer needed.
20 Signed-off-by: Matthias Reichl <hias@horus.com>
22 sound/soc/bcm/justboom-dac.c | 145 +++++++++++++++++++++++++++++++++++
23 1 file changed, 145 insertions(+)
24 create mode 100644 sound/soc/bcm/justboom-dac.c
27 +++ b/sound/soc/bcm/justboom-dac.c
30 + * ASoC Driver for JustBoom DAC Raspberry Pi HAT Sound Card
32 + * Author: Milan Neskovic
34 + * based on code by Daniel Matuschek <info@crazy-audio.com>
35 + * based on code by Florian Meier <florian.meier@koalo.de>
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.
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.
47 +#include <linux/module.h>
48 +#include <linux/platform_device.h>
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>
56 +#include "../codecs/pcm512x.h"
58 +static bool digital_gain_0db_limit = true;
60 +static int snd_rpi_justboom_dac_init(struct snd_soc_pcm_runtime *rtd)
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);
67 + if (digital_gain_0db_limit)
70 + struct snd_soc_card *card = rtd->card;
72 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
74 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
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);
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);
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,
99 +static struct snd_soc_dai_link snd_rpi_justboom_dac_dai[] = {
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,
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),
123 +static int snd_rpi_justboom_dac_probe(struct platform_device *pdev)
127 + snd_rpi_justboom_dac.dev = &pdev->dev;
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);
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;
142 + digital_gain_0db_limit = !of_property_read_bool(
143 + pdev->dev.of_node, "justboom,24db_digital_gain");
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);
154 +static const struct of_device_id snd_rpi_justboom_dac_of_match[] = {
155 + { .compatible = "justboom,justboom-dac", },
158 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_dac_of_match);
160 +static struct platform_driver snd_rpi_justboom_dac_driver = {
162 + .name = "snd-rpi-justboom-dac",
163 + .owner = THIS_MODULE,
164 + .of_match_table = snd_rpi_justboom_dac_of_match,
166 + .probe = snd_rpi_justboom_dac_probe,
169 +module_platform_driver(snd_rpi_justboom_dac_driver);
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");