ath79: add support for TP-LINK Archer C7 v4
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.9 / 950-0082-Add-support-for-Dion-Audio-LOCO-DAC-AMP-HAT.patch
1 From 999d3e615247d1921d245f7084194efbc697bb66 Mon Sep 17 00:00:00 2001
2 From: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
3 Date: Sat, 2 Jul 2016 16:26:19 +0100
4 Subject: [PATCH] Add support for Dion Audio LOCO DAC-AMP HAT
5
6 Using dedicated machine driver and pcm5102a codec driver.
7
8 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
9 ---
10 sound/soc/bcm/Kconfig | 7 +++
11 sound/soc/bcm/Makefile | 3 +-
12 sound/soc/bcm/dionaudio_loco.c | 121 +++++++++++++++++++++++++++++++++++++++++
13 3 files changed, 130 insertions(+), 1 deletion(-)
14 create mode 100644 sound/soc/bcm/dionaudio_loco.c
15
16 --- a/sound/soc/bcm/Kconfig
17 +++ b/sound/soc/bcm/Kconfig
18 @@ -116,3 +116,10 @@ config SND_DIGIDAC1_SOUNDCARD
19 select SND_SOC_WM8741
20 help
21 Say Y or M if you want to add support for Red Rocks Audio DigiDAC1 board.
22 +
23 +config SND_BCM2708_SOC_DIONAUDIO_LOCO
24 + tristate "Support for Dion Audio LOCO DAC-AMP"
25 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
26 + select SND_SOC_PCM5102a
27 + help
28 + Say Y or M if you want to add support for Dion Audio LOCO.
29 --- a/sound/soc/bcm/Makefile
30 +++ b/sound/soc/bcm/Makefile
31 @@ -23,6 +23,7 @@ snd-soc-iqaudio-digi-objs := iqaudio_dig
32 snd-soc-raspidac3-objs := raspidac3.o
33 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
34 snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
35 +snd-soc-dionaudio-loco-objs := dionaudio_loco.o
36
37 obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
38 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
39 @@ -38,4 +39,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DIG
40 obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
41 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
42 obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
43 -
44 +obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
45 --- /dev/null
46 +++ b/sound/soc/bcm/dionaudio_loco.c
47 @@ -0,0 +1,121 @@
48 +/*
49 + * ASoC Driver for Dion Audio LOCO DAC-AMP
50 + *
51 + * Author: Miquel Blauw <info@dionaudio.nl>
52 + * Copyright 2016
53 + *
54 + * Based on the software of the RPi-DAC writen by Florian Meier
55 + *
56 + * This program is free software; you can redistribute it and/or
57 + * modify it under the terms of the GNU General Public License
58 + * version 2 as published by the Free Software Foundation.
59 + *
60 + * This program is distributed in the hope that it will be useful, but
61 + * WITHOUT ANY WARRANTY; without even the implied warranty of
62 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
63 + * General Public License for more details.
64 + */
65 +
66 +#include <linux/module.h>
67 +#include <linux/platform_device.h>
68 +
69 +#include <sound/core.h>
70 +#include <sound/pcm.h>
71 +#include <sound/pcm_params.h>
72 +#include <sound/soc.h>
73 +#include <sound/jack.h>
74 +
75 +static int snd_rpi_dionaudio_loco_hw_params(
76 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
77 +{
78 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
79 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
80 +
81 + unsigned int sample_bits =
82 + snd_pcm_format_physical_width(params_format(params));
83 +
84 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
85 +}
86 +
87 +/* machine stream operations */
88 +static struct snd_soc_ops snd_rpi_dionaudio_loco_ops = {
89 + .hw_params = snd_rpi_dionaudio_loco_hw_params,
90 +};
91 +
92 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_dai[] = {
93 +{
94 + .name = "DionAudio LOCO",
95 + .stream_name = "DionAudio LOCO DAC-AMP",
96 + .cpu_dai_name = "bcm2708-i2s.0",
97 + .codec_dai_name = "pcm5102a-hifi",
98 + .platform_name = "bcm2708-i2s.0",
99 + .codec_name = "pcm5102a-codec",
100 + .dai_fmt = SND_SOC_DAIFMT_I2S |
101 + SND_SOC_DAIFMT_NB_NF |
102 + SND_SOC_DAIFMT_CBS_CFS,
103 + .ops = &snd_rpi_dionaudio_loco_ops,
104 +},
105 +};
106 +
107 +/* audio machine driver */
108 +static struct snd_soc_card snd_rpi_dionaudio_loco = {
109 + .name = "snd_rpi_dionaudio_loco",
110 + .dai_link = snd_rpi_dionaudio_loco_dai,
111 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_dai),
112 +};
113 +
114 +static int snd_rpi_dionaudio_loco_probe(struct platform_device *pdev)
115 +{
116 + struct device_node *np;
117 + int ret = 0;
118 +
119 + snd_rpi_dionaudio_loco.dev = &pdev->dev;
120 +
121 + np = pdev->dev.of_node;
122 + if (np) {
123 + struct snd_soc_dai_link *dai = &snd_rpi_dionaudio_loco_dai[0];
124 + struct device_node *i2s_np;
125 +
126 + i2s_np = of_parse_phandle(np, "i2s-controller", 0);
127 + if (i2s_np) {
128 + dai->cpu_dai_name = NULL;
129 + dai->cpu_of_node = i2s_np;
130 + dai->platform_name = NULL;
131 + dai->platform_of_node = i2s_np;
132 + }
133 + }
134 +
135 + ret = snd_soc_register_card(&snd_rpi_dionaudio_loco);
136 + if (ret)
137 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
138 + ret);
139 +
140 + return ret;
141 +}
142 +
143 +static int snd_rpi_dionaudio_loco_remove(struct platform_device *pdev)
144 +{
145 + return snd_soc_unregister_card(&snd_rpi_dionaudio_loco);
146 +}
147 +
148 +static const struct of_device_id snd_rpi_dionaudio_loco_of_match[] = {
149 + { .compatible = "dionaudio,loco-pcm5242-tpa3118", },
150 + { /* sentinel */ },
151 +};
152 +MODULE_DEVICE_TABLE(of, snd_rpi_dionaudio_loco_of_match);
153 +
154 +static struct platform_driver snd_rpi_dionaudio_loco_driver = {
155 + .driver = {
156 + .name = "snd-dionaudio-loco",
157 + .owner = THIS_MODULE,
158 + .of_match_table = snd_rpi_dionaudio_loco_of_match,
159 + },
160 + .probe = snd_rpi_dionaudio_loco_probe,
161 + .remove = snd_rpi_dionaudio_loco_remove,
162 +};
163 +
164 +module_platform_driver(snd_rpi_dionaudio_loco_driver);
165 +
166 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
167 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO");
168 +MODULE_LICENSE("GPL v2");