545869ae669206f6c06f441d84bec2466c8390df
[15.05/openwrt.git] / target / linux / brcm2708 / patches-3.18 / 0060-Added-support-for-HiFiBerry-DAC.patch
1 From fb7a1cc51aee2d66232d3a170e1343dfbb7b3485 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 060/114] 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  arch/arm/configs/bcmrpi_defconfig |   1 +
10  arch/arm/mach-bcm2708/bcm2708.c   |  19 ++++++
11  sound/soc/bcm/Kconfig             |   7 +++
12  sound/soc/bcm/Makefile            |   2 +
13  sound/soc/bcm/hifiberry_dacplus.c | 119 ++++++++++++++++++++++++++++++++++++++
14  5 files changed, 148 insertions(+)
15  create mode 100644 sound/soc/bcm/hifiberry_dacplus.c
16
17 diff --git a/arch/arm/configs/bcmrpi_defconfig b/arch/arm/configs/bcmrpi_defconfig
18 index c363a10..28547eb 100644
19 --- a/arch/arm/configs/bcmrpi_defconfig
20 +++ b/arch/arm/configs/bcmrpi_defconfig
21 @@ -756,6 +756,7 @@ CONFIG_SND_USB_6FIRE=m
22  CONFIG_SND_SOC=m
23  CONFIG_SND_BCM2708_SOC_I2S=m
24  CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
25 +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
26  CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
27  CONFIG_SND_BCM2708_SOC_RPI_DAC=m
28  CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
29 diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c
30 index 5ff1299..aa62e55 100644
31 --- a/arch/arm/mach-bcm2708/bcm2708.c
32 +++ b/arch/arm/mach-bcm2708/bcm2708.c
33 @@ -645,6 +645,20 @@ static struct platform_device snd_pcm5102a_codec_device = {
34  };
35  #endif
36  
37 +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
38 +static struct platform_device snd_rpi_hifiberry_dacplus_device = {
39 +        .name = "snd-rpi-hifiberry-dacplus",
40 +        .id = 0,
41 +        .num_resources = 0,
42 +};
43 +
44 +static struct i2c_board_info __initdata snd_pcm512x_hbdacplus_i2c_devices[] = {
45 +        {
46 +                I2C_BOARD_INFO("pcm5122", 0x4d)
47 +        },
48 +};
49 +#endif
50 +
51  #if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
52  static struct platform_device snd_hifiberry_digi_device = {
53          .name = "snd-hifiberry-digi",
54 @@ -845,6 +859,11 @@ void __init bcm2708_init(void)
55          bcm_register_device(&snd_pcm5102a_codec_device);
56  #endif
57  
58 +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
59 +        bcm_register_device(&snd_rpi_hifiberry_dacplus_device);
60 +        i2c_register_board_info(1, snd_pcm512x_hbdacplus_i2c_devices, ARRAY_SIZE(snd_pcm512x_hbdacplus_i2c_devices));
61 +#endif
62 +
63  #if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
64          bcm_register_device(&snd_hifiberry_digi_device);
65          i2c_register_board_info(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
66 diff --git a/sound/soc/bcm/Kconfig b/sound/soc/bcm/Kconfig
67 index c621a5e..926a82b 100644
68 --- a/sound/soc/bcm/Kconfig
69 +++ b/sound/soc/bcm/Kconfig
70 @@ -26,6 +26,13 @@ config SND_BCM2708_SOC_HIFIBERRY_DAC
71          help
72           Say Y or M if you want to add support for HifiBerry DAC.
73  
74 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
75 +        tristate "Support for HifiBerry DAC+"
76 +        depends on SND_BCM2708_SOC_I2S
77 +        select SND_SOC_PCM512x
78 +        help
79 +         Say Y or M if you want to add support for HifiBerry DAC+.
80 +
81  config SND_BCM2708_SOC_HIFIBERRY_DIGI
82          tristate "Support for HifiBerry Digi"
83          depends on SND_BCM2708_SOC_I2S
84 diff --git a/sound/soc/bcm/Makefile b/sound/soc/bcm/Makefile
85 index d597fb0..c02e3a2 100644
86 --- a/sound/soc/bcm/Makefile
87 +++ b/sound/soc/bcm/Makefile
88 @@ -10,11 +10,13 @@ obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
89  
90  # BCM2708 Machine Support
91  snd-soc-hifiberry-dac-objs := hifiberry_dac.o
92 +snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
93  snd-soc-hifiberry-digi-objs := hifiberry_digi.o
94  snd-soc-rpi-dac-objs := rpi-dac.o
95  snd-soc-iqaudio-dac-objs := iqaudio-dac.o
96  
97  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
98 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
99  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
100  obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
101  obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
102 diff --git a/sound/soc/bcm/hifiberry_dacplus.c b/sound/soc/bcm/hifiberry_dacplus.c
103 new file mode 100644
104 index 0000000..c63387b
105 --- /dev/null
106 +++ b/sound/soc/bcm/hifiberry_dacplus.c
107 @@ -0,0 +1,119 @@
108 +/*
109 + * ASoC Driver for HiFiBerry DAC+
110 + *
111 + * Author:     Daniel Matuschek
112 + *             Copyright 2014
113 + *             based on code by Florian Meier <florian.meier@koalo.de>
114 + *
115 + * This program is free software; you can redistribute it and/or
116 + * modify it under the terms of the GNU General Public License
117 + * version 2 as published by the Free Software Foundation.
118 + *
119 + * This program is distributed in the hope that it will be useful, but
120 + * WITHOUT ANY WARRANTY; without even the implied warranty of
121 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
122 + * General Public License for more details.
123 + */
124 +
125 +#include <linux/module.h>
126 +#include <linux/platform_device.h>
127 +
128 +#include <sound/core.h>
129 +#include <sound/pcm.h>
130 +#include <sound/pcm_params.h>
131 +#include <sound/soc.h>
132 +#include <sound/jack.h>
133 +
134 +#include "../codecs/pcm512x.h"
135 +
136 +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
137 +{
138 +       struct snd_soc_codec *codec = rtd->codec;
139 +       snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
140 +       snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
141 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
142 +       return 0;
143 +}
144 +
145 +static int snd_rpi_hifiberry_dacplus_hw_params(struct snd_pcm_substream *substream,
146 +                                      struct snd_pcm_hw_params *params)
147 +{
148 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
149 +       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
150 +       return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
151 +}
152 +
153 +static int snd_rpi_hifiberry_dacplus_startup(struct snd_pcm_substream *substream) {
154 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
155 +       struct snd_soc_codec *codec = rtd->codec;
156 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
157 +       return 0;
158 +}
159 +
160 +static void snd_rpi_hifiberry_dacplus_shutdown(struct snd_pcm_substream *substream) {
161 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
162 +       struct snd_soc_codec *codec = rtd->codec;
163 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
164 +}
165 +
166 +/* machine stream operations */
167 +static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = {
168 +       .hw_params = snd_rpi_hifiberry_dacplus_hw_params,
169 +       .startup = snd_rpi_hifiberry_dacplus_startup,
170 +       .shutdown = snd_rpi_hifiberry_dacplus_shutdown,
171 +};
172 +
173 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
174 +{
175 +       .name           = "HiFiBerry DAC+",
176 +       .stream_name    = "HiFiBerry DAC+ HiFi",
177 +       .cpu_dai_name   = "bcm2708-i2s.0",
178 +       .codec_dai_name = "pcm512x-hifi",
179 +       .platform_name  = "bcm2708-i2s.0",
180 +       .codec_name     = "pcm512x.1-004d",
181 +       .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
182 +                               SND_SOC_DAIFMT_CBS_CFS,
183 +       .ops            = &snd_rpi_hifiberry_dacplus_ops,
184 +       .init           = snd_rpi_hifiberry_dacplus_init,
185 +},
186 +};
187 +
188 +/* audio machine driver */
189 +static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
190 +       .name         = "snd_rpi_hifiberry_dacplus",
191 +       .dai_link     = snd_rpi_hifiberry_dacplus_dai,
192 +       .num_links    = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
193 +};
194 +
195 +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
196 +{
197 +       int ret = 0;
198 +
199 +       snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
200 +       ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplus);
201 +       if (ret)
202 +               dev_err(&pdev->dev,
203 +                       "snd_soc_register_card() failed: %d\n", ret);
204 +
205 +       return ret;
206 +}
207 +
208 +static int snd_rpi_hifiberry_dacplus_remove(struct platform_device *pdev)
209 +{
210 +       return snd_soc_unregister_card(&snd_rpi_hifiberry_dacplus);
211 +}
212 +
213 +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
214 +       .driver = {
215 +               .name   = "snd-rpi-hifiberry-dacplus",
216 +               .owner  = THIS_MODULE,
217 +       },
218 +       .probe          = snd_rpi_hifiberry_dacplus_probe,
219 +       .remove         = snd_rpi_hifiberry_dacplus_remove,
220 +};
221 +
222 +module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
223 +
224 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
225 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
226 +MODULE_LICENSE("GPL v2");
227 -- 
228 1.8.3.2
229