]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - sound/soc/bcm/allo-piano-dac.c
sound: Suppress error message about deferrals
[mirror_ubuntu-zesty-kernel.git] / sound / soc / bcm / allo-piano-dac.c
CommitLineData
1a3a1cb1
CM
1/*
2 * ALSA ASoC Machine Driver for Allo Piano DAC
3 *
4 * Author: Baswaraj K <jaikumar@cem-solutions.net>
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
27static bool digital_gain_0db_limit = true;
28
29static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
30{
31 if (digital_gain_0db_limit) {
32 int ret;
33 struct snd_soc_card *card = rtd->card;
34
35 ret = snd_soc_limit_volume(card, "Digital Playback Volume",
36 207);
37 if (ret < 0)
38 dev_warn(card->dev, "Failed to set volume limit: %d\n",
39 ret);
40 }
41
42 return 0;
43}
44
45static int snd_allo_piano_dac_hw_params(
46 struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
47{
48 struct snd_soc_pcm_runtime *rtd = substream->private_data;
49 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
50
51 unsigned int sample_bits =
52 snd_pcm_format_physical_width(params_format(params));
53
54 return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
55}
56
57/* machine stream operations */
58static struct snd_soc_ops snd_allo_piano_dac_ops = {
59 .hw_params = snd_allo_piano_dac_hw_params,
60};
61
62static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
63{
64 .name = "Piano DAC",
65 .stream_name = "Piano DAC HiFi",
66 .cpu_dai_name = "bcm2708-i2s.0",
67 .codec_dai_name = "pcm512x-hifi",
68 .platform_name = "bcm2708-i2s.0",
69 .codec_name = "pcm512x.1-004c",
70 .dai_fmt = SND_SOC_DAIFMT_I2S |
71 SND_SOC_DAIFMT_NB_NF |
72 SND_SOC_DAIFMT_CBS_CFS,
73 .ops = &snd_allo_piano_dac_ops,
74 .init = snd_allo_piano_dac_init,
75},
76};
77
78/* audio machine driver */
79static struct snd_soc_card snd_allo_piano_dac = {
80 .name = "PianoDAC",
81 .owner = THIS_MODULE,
82 .dai_link = snd_allo_piano_dac_dai,
83 .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
84};
85
86static int snd_allo_piano_dac_probe(struct platform_device *pdev)
87{
88 int ret = 0;
89
90 snd_allo_piano_dac.dev = &pdev->dev;
91
92 if (pdev->dev.of_node) {
93 struct device_node *i2s_node;
94 struct snd_soc_dai_link *dai;
95
96 dai = &snd_allo_piano_dac_dai[0];
97 i2s_node = of_parse_phandle(pdev->dev.of_node,
98 "i2s-controller", 0);
99
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, "allo,24db_digital_gain");
109 }
110
111 ret = snd_soc_register_card(&snd_allo_piano_dac);
49dbf1af 112 if (ret && ret != -EPROBE_DEFER)
1a3a1cb1
CM
113 dev_err(&pdev->dev,
114 "snd_soc_register_card() failed: %d\n", ret);
115
116 return ret;
117}
118
119static int snd_allo_piano_dac_remove(struct platform_device *pdev)
120{
121 return snd_soc_unregister_card(&snd_allo_piano_dac);
122}
123
124static const struct of_device_id snd_allo_piano_dac_of_match[] = {
125 { .compatible = "allo,piano-dac", },
126 { /* sentinel */ },
127};
128MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
129
130static struct platform_driver snd_allo_piano_dac_driver = {
131 .driver = {
132 .name = "snd-allo-piano-dac",
133 .owner = THIS_MODULE,
134 .of_match_table = snd_allo_piano_dac_of_match,
135 },
136 .probe = snd_allo_piano_dac_probe,
137 .remove = snd_allo_piano_dac_remove,
138};
139
140module_platform_driver(snd_allo_piano_dac_driver);
141
142MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
143MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC");
144MODULE_LICENSE("GPL v2");