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