brcm2708: update 3.10 patches with raspberrypi/rpi-3.10.y of 27 Apr. 2014
[openwrt.git] / target / linux / brcm2708 / patches-3.10 / 0157-ASoC-BCM-Add-support-for-HiFiBerry-Digi.patch
1 From 4800df016d86e646023966b727915a06f9c9ccd9 Mon Sep 17 00:00:00 2001
2 From: Daniel Matuschek <info@crazy-audio.com>
3 Date: Wed, 15 Jan 2014 21:42:08 +0100
4 Subject: [PATCH 157/196] ASoC: BCM:Add support for HiFiBerry Digi. Driver is
5  based on the patched WM8804 driver.
6
7 Signed-off-by: Daniel Matuschek <daniel@matuschek.net>
8 ---
9  sound/soc/bcm/Kconfig          |   9 ++-
10  sound/soc/bcm/Makefile         |   2 +
11  sound/soc/bcm/hifiberry_digi.c | 153 +++++++++++++++++++++++++++++++++++++++++
12  3 files changed, 163 insertions(+), 1 deletion(-)
13  create mode 100644 sound/soc/bcm/hifiberry_digi.c
14
15 diff --git a/sound/soc/bcm/Kconfig b/sound/soc/bcm/Kconfig
16 index 1c1f5cf..7e2afc2 100644
17 --- a/sound/soc/bcm/Kconfig
18 +++ b/sound/soc/bcm/Kconfig
19 @@ -16,9 +16,16 @@ config SND_BCM2708_SOC_HIFIBERRY_DAC
20          help
21           Say Y or M if you want to add support for HifiBerry DAC.
22  
23 +config SND_BCM2708_SOC_HIFIBERRY_DIGI
24 +        tristate "Support for HifiBerry Digi"
25 +        depends on SND_BCM2708_SOC_I2S
26 +        select SND_SOC_WM8804
27 +        help
28 +         Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
29 +
30  config SND_BCM2708_SOC_RPI_DAC
31          tristate "Support for RPi-DAC"
32          depends on SND_BCM2708_SOC_I2S
33          select SND_SOC_PCM1794A
34          help
35 -         Say Y or M if you want to add support for RPi-DAC.
36 \ No newline at end of file
37 +         Say Y or M if you want to add support for RPi-DAC.
38 diff --git a/sound/soc/bcm/Makefile b/sound/soc/bcm/Makefile
39 index 95a9d44..54e37eb 100644
40 --- a/sound/soc/bcm/Makefile
41 +++ b/sound/soc/bcm/Makefile
42 @@ -5,7 +5,9 @@ obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
43  
44  # BCM2708 Machine Support
45  snd-soc-hifiberry-dac-objs := hifiberry_dac.o
46 +snd-soc-hifiberry-digi-objs := hifiberry_digi.o
47  snd-soc-rpi-dac-objs := rpi-dac.o
48  
49  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
50 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
51  obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
52 diff --git a/sound/soc/bcm/hifiberry_digi.c b/sound/soc/bcm/hifiberry_digi.c
53 new file mode 100644
54 index 0000000..5b37e66
55 --- /dev/null
56 +++ b/sound/soc/bcm/hifiberry_digi.c
57 @@ -0,0 +1,153 @@
58 +/*
59 + * ASoC Driver for HifiBerry Digi
60 + *
61 + * Author: Daniel Matuschek <info@crazy-audio.com>
62 + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
63 + *     Copyright 2013
64 + *
65 + * This program is free software; you can redistribute it and/or
66 + * modify it under the terms of the GNU General Public License
67 + * version 2 as published by the Free Software Foundation.
68 + *
69 + * This program is distributed in the hope that it will be useful, but
70 + * WITHOUT ANY WARRANTY; without even the implied warranty of
71 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
72 + * General Public License for more details.
73 + */
74 +
75 +#include <linux/module.h>
76 +#include <linux/platform_device.h>
77 +
78 +#include <sound/core.h>
79 +#include <sound/pcm.h>
80 +#include <sound/pcm_params.h>
81 +#include <sound/soc.h>
82 +#include <sound/jack.h>
83 +
84 +#include "../codecs/wm8804.h"
85 +
86 +static int samplerate=44100;
87 +
88 +static int snd_rpi_hifiberry_digi_init(struct snd_soc_pcm_runtime *rtd)
89 +{
90 +       struct snd_soc_codec *codec = rtd->codec;
91 +
92 +       /* enable TX output */
93 +       snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
94 +       
95 +       return 0;
96 +}
97 +
98 +static int snd_rpi_hifiberry_digi_hw_params(struct snd_pcm_substream *substream,
99 +                                      struct snd_pcm_hw_params *params)
100 +{
101 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
102 +       struct snd_soc_dai *codec_dai = rtd->codec_dai;
103 +       struct snd_soc_codec *codec = rtd->codec;
104 +       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
105 +       
106 +       int sysclk = 27000000; /* This is fixed on this board */
107 +
108 +       long mclk_freq=0;
109 +       int mclk_div=1;
110 +       
111 +       int ret;
112 +
113 +       samplerate = params_rate(params);
114 +
115 +       switch (samplerate) {
116 +               case 44100:     
117 +               case 48000:
118 +               case 88200:
119 +               case 96000:
120 +                       mclk_freq=samplerate*256;
121 +                       mclk_div=WM8804_MCLKDIV_256FS;
122 +                       break;
123 +               case 176400:
124 +               case 192000:
125 +                       mclk_freq=samplerate*128;
126 +                       mclk_div=WM8804_MCLKDIV_128FS;
127 +                       break;
128 +               default:
129 +                       dev_err(substream->pcm->dev, 
130 +                       "Failed to set WM8804 SYSCLK, unsupported samplerate\n");
131 +       }
132 +
133 +       snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
134 +       snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
135 +
136 +       ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
137 +                                       sysclk, SND_SOC_CLOCK_OUT);
138 +       if (ret < 0) {
139 +               dev_err(substream->pcm->dev,
140 +               "Failed to set WM8804 SYSCLK: %d\n", ret);
141 +               return ret;
142 +       }
143 +
144 +       /* Enable TX output */
145 +       snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
146 +       
147 +       /* Power on */
148 +       snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
149 +
150 +       return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
151 +}
152 +
153 +/* machine stream operations */
154 +static struct snd_soc_ops snd_rpi_hifiberry_digi_ops = {
155 +       .hw_params = snd_rpi_hifiberry_digi_hw_params,
156 +};
157 +
158 +static struct snd_soc_dai_link snd_rpi_hifiberry_digi_dai[] = {
159 +{
160 +       .name           = "HifiBerry Digi",
161 +       .stream_name    = "HifiBerry Digi HiFi",
162 +       .cpu_dai_name   = "bcm2708-i2s.0",
163 +       .codec_dai_name = "wm8804-spdif",
164 +       .platform_name  = "bcm2708-i2s.0",
165 +       .codec_name     = "wm8804.1-003b",
166 +       .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
167 +                               SND_SOC_DAIFMT_CBM_CFM,
168 +       .ops            = &snd_rpi_hifiberry_digi_ops,
169 +       .init           = snd_rpi_hifiberry_digi_init,
170 +},
171 +};
172 +
173 +/* audio machine driver */
174 +static struct snd_soc_card snd_rpi_hifiberry_digi = {
175 +       .name         = "snd_rpi_hifiberry_digi",
176 +       .dai_link     = snd_rpi_hifiberry_digi_dai,
177 +       .num_links    = ARRAY_SIZE(snd_rpi_hifiberry_digi_dai),
178 +};
179 +
180 +static int snd_rpi_hifiberry_digi_probe(struct platform_device *pdev)
181 +{
182 +       int ret = 0;
183 +
184 +       snd_rpi_hifiberry_digi.dev = &pdev->dev;
185 +       ret = snd_soc_register_card(&snd_rpi_hifiberry_digi);
186 +       if (ret)
187 +               dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
188 +
189 +       return ret;
190 +}
191 +
192 +static int snd_rpi_hifiberry_digi_remove(struct platform_device *pdev)
193 +{
194 +       return snd_soc_unregister_card(&snd_rpi_hifiberry_digi);
195 +}
196 +
197 +static struct platform_driver snd_rpi_hifiberry_digi_driver = {
198 +       .driver = {
199 +               .name   = "snd-hifiberry-digi",
200 +               .owner  = THIS_MODULE,
201 +       },
202 +       .probe          = snd_rpi_hifiberry_digi_probe,
203 +       .remove         = snd_rpi_hifiberry_digi_remove,
204 +};
205 +
206 +module_platform_driver(snd_rpi_hifiberry_digi_driver);
207 +
208 +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
209 +MODULE_DESCRIPTION("ASoC Driver for HifiBerry Digi");
210 +MODULE_LICENSE("GPL v2");
211 -- 
212 1.9.1
213