2c2ed05b6363a6b4eaed0e8686dfeb8627e7a69a
[openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0071-Added-support-for-HiFiBerry-DAC.patch
1 From 21d1427a7563d56ca1fdcee66cb80e7f2879c6b8 Mon Sep 17 00:00:00 2001
2 From: Daniel Matuschek <info@crazy-audio.com>
3 Date: Mon, 4 Aug 2014 10:06:56 +0200
4 Subject: [PATCH 071/127] Added support for HiFiBerry DAC+
5
6 The driver is based on the HiFiBerry DAC driver. However HiFiBerry DAC+ uses
7 a different codec chip (PCM5122), therefore a new driver is necessary.
8 ---
9  sound/soc/bcm/Kconfig             |   7 ++
10  sound/soc/bcm/Makefile            |   2 +
11  sound/soc/bcm/hifiberry_dacplus.c | 141 ++++++++++++++++++++++++++++++++++++++
12  3 files changed, 150 insertions(+)
13  create mode 100644 sound/soc/bcm/hifiberry_dacplus.c
14
15 --- a/sound/soc/bcm/Kconfig
16 +++ b/sound/soc/bcm/Kconfig
17 @@ -15,6 +15,13 @@ config SND_BCM2708_SOC_HIFIBERRY_DAC
18          help
19           Say Y or M if you want to add support for HifiBerry DAC.
20  
21 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
22 +        tristate "Support for HifiBerry DAC+"
23 +        depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
24 +        select SND_SOC_PCM512x
25 +        help
26 +         Say Y or M if you want to add support for HifiBerry DAC+.
27 +
28  config SND_BCM2708_SOC_HIFIBERRY_DIGI
29          tristate "Support for HifiBerry Digi"
30          depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
31 --- a/sound/soc/bcm/Makefile
32 +++ b/sound/soc/bcm/Makefile
33 @@ -5,11 +5,13 @@ obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd
34  
35  # BCM2708 Machine Support
36  snd-soc-hifiberry-dac-objs := hifiberry_dac.o
37 +snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
38  snd-soc-hifiberry-digi-objs := hifiberry_digi.o
39  snd-soc-rpi-dac-objs := rpi-dac.o
40  snd-soc-iqaudio-dac-objs := iqaudio-dac.o
41  
42  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
43 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
44  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
45  obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
46  obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
47 --- /dev/null
48 +++ b/sound/soc/bcm/hifiberry_dacplus.c
49 @@ -0,0 +1,141 @@
50 +/*
51 + * ASoC Driver for HiFiBerry DAC+
52 + *
53 + * Author:     Daniel Matuschek
54 + *             Copyright 2014
55 + *             based on code by Florian Meier <florian.meier@koalo.de>
56 + *
57 + * This program is free software; you can redistribute it and/or
58 + * modify it under the terms of the GNU General Public License
59 + * version 2 as published by the Free Software Foundation.
60 + *
61 + * This program is distributed in the hope that it will be useful, but
62 + * WITHOUT ANY WARRANTY; without even the implied warranty of
63 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
64 + * General Public License for more details.
65 + */
66 +
67 +#include <linux/module.h>
68 +#include <linux/platform_device.h>
69 +
70 +#include <sound/core.h>
71 +#include <sound/pcm.h>
72 +#include <sound/pcm_params.h>
73 +#include <sound/soc.h>
74 +#include <sound/jack.h>
75 +
76 +#include "../codecs/pcm512x.h"
77 +
78 +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
79 +{
80 +       struct snd_soc_codec *codec = rtd->codec;
81 +       snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
82 +       snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
83 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
84 +       return 0;
85 +}
86 +
87 +static int snd_rpi_hifiberry_dacplus_hw_params(struct snd_pcm_substream *substream,
88 +                                      struct snd_pcm_hw_params *params)
89 +{
90 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
91 +       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
92 +       return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
93 +}
94 +
95 +static int snd_rpi_hifiberry_dacplus_startup(struct snd_pcm_substream *substream) {
96 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
97 +       struct snd_soc_codec *codec = rtd->codec;
98 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
99 +       return 0;
100 +}
101 +
102 +static void snd_rpi_hifiberry_dacplus_shutdown(struct snd_pcm_substream *substream) {
103 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
104 +       struct snd_soc_codec *codec = rtd->codec;
105 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
106 +}
107 +
108 +/* machine stream operations */
109 +static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = {
110 +       .hw_params = snd_rpi_hifiberry_dacplus_hw_params,
111 +       .startup = snd_rpi_hifiberry_dacplus_startup,
112 +       .shutdown = snd_rpi_hifiberry_dacplus_shutdown,
113 +};
114 +
115 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
116 +{
117 +       .name           = "HiFiBerry DAC+",
118 +       .stream_name    = "HiFiBerry DAC+ HiFi",
119 +       .cpu_dai_name   = "bcm2708-i2s.0",
120 +       .codec_dai_name = "pcm512x-hifi",
121 +       .platform_name  = "bcm2708-i2s.0",
122 +       .codec_name     = "pcm512x.1-004d",
123 +       .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
124 +                               SND_SOC_DAIFMT_CBS_CFS,
125 +       .ops            = &snd_rpi_hifiberry_dacplus_ops,
126 +       .init           = snd_rpi_hifiberry_dacplus_init,
127 +},
128 +};
129 +
130 +/* audio machine driver */
131 +static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
132 +       .name         = "snd_rpi_hifiberry_dacplus",
133 +       .dai_link     = snd_rpi_hifiberry_dacplus_dai,
134 +       .num_links    = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
135 +};
136 +
137 +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
138 +{
139 +       int ret = 0;
140 +
141 +       snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
142 +
143 +       if (pdev->dev.of_node) {
144 +           struct device_node *i2s_node;
145 +           struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_dacplus_dai[0];
146 +           i2s_node = of_parse_phandle(pdev->dev.of_node,
147 +                                       "i2s-controller", 0);
148 +
149 +           if (i2s_node) {
150 +               dai->cpu_dai_name = NULL;
151 +               dai->cpu_of_node = i2s_node;
152 +               dai->platform_name = NULL;
153 +               dai->platform_of_node = i2s_node;
154 +           }
155 +       }
156 +
157 +       ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplus);
158 +       if (ret)
159 +               dev_err(&pdev->dev,
160 +                       "snd_soc_register_card() failed: %d\n", ret);
161 +
162 +       return ret;
163 +}
164 +
165 +static int snd_rpi_hifiberry_dacplus_remove(struct platform_device *pdev)
166 +{
167 +       return snd_soc_unregister_card(&snd_rpi_hifiberry_dacplus);
168 +}
169 +
170 +static const struct of_device_id snd_rpi_hifiberry_dacplus_of_match[] = {
171 +       { .compatible = "hifiberry,hifiberry-dacplus", },
172 +       {},
173 +};
174 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplus_of_match);
175 +
176 +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
177 +       .driver = {
178 +               .name   = "snd-rpi-hifiberry-dacplus",
179 +               .owner  = THIS_MODULE,
180 +               .of_match_table = snd_rpi_hifiberry_dacplus_of_match,
181 +       },
182 +       .probe          = snd_rpi_hifiberry_dacplus_probe,
183 +       .remove         = snd_rpi_hifiberry_dacplus_remove,
184 +};
185 +
186 +module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
187 +
188 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
189 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
190 +MODULE_LICENSE("GPL v2");