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