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