]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - sound/soc/bcm/justboom-dac.c
ASoC: justboom-dac: fix S24_LE format
[mirror_ubuntu-bionic-kernel.git] / sound / soc / bcm / justboom-dac.c
CommitLineData
359d0ac8
AS
1/*
2 * ASoC Driver for JustBoom DAC Raspberry Pi HAT Sound Card
3 *
4 * Author: Milan Neskovic
5 * Copyright 2016
6 * based on code by Daniel Matuschek <info@crazy-audio.com>
7 * based on code by Florian Meier <florian.meier@koalo.de>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 */
18
19#include <linux/module.h>
20#include <linux/platform_device.h>
21
22#include <sound/core.h>
23#include <sound/pcm.h>
24#include <sound/pcm_params.h>
25#include <sound/soc.h>
26#include <sound/jack.h>
27
28#include "../codecs/pcm512x.h"
29
30static bool digital_gain_0db_limit = true;
31
32static int snd_rpi_justboom_dac_init(struct snd_soc_pcm_runtime *rtd)
33{
34 struct snd_soc_codec *codec = rtd->codec;
35 snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
36 snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
37 snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
38
39 if (digital_gain_0db_limit)
40 {
41 int ret;
42 struct snd_soc_card *card = rtd->card;
43
44 ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
45 if (ret < 0)
46 dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
47 }
48
49 return 0;
50}
51
359d0ac8
AS
52static int snd_rpi_justboom_dac_startup(struct snd_pcm_substream *substream) {
53 struct snd_soc_pcm_runtime *rtd = substream->private_data;
54 struct snd_soc_codec *codec = rtd->codec;
55 snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
56 return 0;
57}
58
59static void snd_rpi_justboom_dac_shutdown(struct snd_pcm_substream *substream) {
60 struct snd_soc_pcm_runtime *rtd = substream->private_data;
61 struct snd_soc_codec *codec = rtd->codec;
62 snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
63}
64
65/* machine stream operations */
66static struct snd_soc_ops snd_rpi_justboom_dac_ops = {
359d0ac8
AS
67 .startup = snd_rpi_justboom_dac_startup,
68 .shutdown = snd_rpi_justboom_dac_shutdown,
69};
70
71static struct snd_soc_dai_link snd_rpi_justboom_dac_dai[] = {
72{
73 .name = "JustBoom DAC",
74 .stream_name = "JustBoom DAC HiFi",
75 .cpu_dai_name = "bcm2708-i2s.0",
76 .codec_dai_name = "pcm512x-hifi",
77 .platform_name = "bcm2708-i2s.0",
78 .codec_name = "pcm512x.1-004d",
79 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
80 SND_SOC_DAIFMT_CBS_CFS,
81 .ops = &snd_rpi_justboom_dac_ops,
82 .init = snd_rpi_justboom_dac_init,
83},
84};
85
86/* audio machine driver */
87static struct snd_soc_card snd_rpi_justboom_dac = {
88 .name = "snd_rpi_justboom_dac",
89 .driver_name = "JustBoomDac",
90 .owner = THIS_MODULE,
91 .dai_link = snd_rpi_justboom_dac_dai,
92 .num_links = ARRAY_SIZE(snd_rpi_justboom_dac_dai),
93};
94
95static int snd_rpi_justboom_dac_probe(struct platform_device *pdev)
96{
97 int ret = 0;
98
99 snd_rpi_justboom_dac.dev = &pdev->dev;
100
101 if (pdev->dev.of_node) {
102 struct device_node *i2s_node;
103 struct snd_soc_dai_link *dai = &snd_rpi_justboom_dac_dai[0];
104 i2s_node = of_parse_phandle(pdev->dev.of_node,
105 "i2s-controller", 0);
106
107 if (i2s_node) {
108 dai->cpu_dai_name = NULL;
109 dai->cpu_of_node = i2s_node;
110 dai->platform_name = NULL;
111 dai->platform_of_node = i2s_node;
112 }
113
114 digital_gain_0db_limit = !of_property_read_bool(
115 pdev->dev.of_node, "justboom,24db_digital_gain");
116 }
117
118 ret = snd_soc_register_card(&snd_rpi_justboom_dac);
119 if (ret && ret != -EPROBE_DEFER)
120 dev_err(&pdev->dev,
121 "snd_soc_register_card() failed: %d\n", ret);
122
123 return ret;
124}
125
126static int snd_rpi_justboom_dac_remove(struct platform_device *pdev)
127{
128 return snd_soc_unregister_card(&snd_rpi_justboom_dac);
129}
130
131static const struct of_device_id snd_rpi_justboom_dac_of_match[] = {
132 { .compatible = "justboom,justboom-dac", },
133 {},
134};
135MODULE_DEVICE_TABLE(of, snd_rpi_justboom_dac_of_match);
136
137static struct platform_driver snd_rpi_justboom_dac_driver = {
138 .driver = {
139 .name = "snd-rpi-justboom-dac",
140 .owner = THIS_MODULE,
141 .of_match_table = snd_rpi_justboom_dac_of_match,
142 },
143 .probe = snd_rpi_justboom_dac_probe,
144 .remove = snd_rpi_justboom_dac_remove,
145};
146
147module_platform_driver(snd_rpi_justboom_dac_driver);
148
149MODULE_AUTHOR("Milan Neskovic <info@justboom.co>");
150MODULE_DESCRIPTION("ASoC Driver for JustBoom PI DAC HAT Sound Card");
151MODULE_LICENSE("GPL v2");