brcm2708: rename target to bcm27xx
[openwrt/staging/wigyori.git] / target / linux / bcm27xx / patches-4.19 / 950-0073-Add-support-for-Dion-Audio-LOCO-DAC-AMP-HAT.patch
1 From 234b6a3cfd5bc1fb341c01f8ac773956f5af42cd 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/dionaudio_loco.c | 115 +++++++++++++++++++++++++++++++++
11 1 file changed, 115 insertions(+)
12 create mode 100644 sound/soc/bcm/dionaudio_loco.c
13
14 --- /dev/null
15 +++ b/sound/soc/bcm/dionaudio_loco.c
16 @@ -0,0 +1,115 @@
17 +/*
18 + * ASoC Driver for Dion Audio LOCO DAC-AMP
19 + *
20 + * Author: Miquel Blauw <info@dionaudio.nl>
21 + * Copyright 2016
22 + *
23 + * Based on the software of the RPi-DAC writen by Florian Meier
24 + *
25 + * This program is free software; you can redistribute it and/or
26 + * modify it under the terms of the GNU General Public License
27 + * version 2 as published by the Free Software Foundation.
28 + *
29 + * This program is distributed in the hope that it will be useful, but
30 + * WITHOUT ANY WARRANTY; without even the implied warranty of
31 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32 + * General Public License for more details.
33 + */
34 +
35 +#include <linux/module.h>
36 +#include <linux/platform_device.h>
37 +
38 +#include <sound/core.h>
39 +#include <sound/pcm.h>
40 +#include <sound/pcm_params.h>
41 +#include <sound/soc.h>
42 +#include <sound/jack.h>
43 +
44 +static int snd_rpi_dionaudio_loco_hw_params(
45 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
46 +{
47 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
48 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
49 +
50 + unsigned int sample_bits =
51 + snd_pcm_format_physical_width(params_format(params));
52 +
53 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
54 +}
55 +
56 +/* machine stream operations */
57 +static struct snd_soc_ops snd_rpi_dionaudio_loco_ops = {
58 + .hw_params = snd_rpi_dionaudio_loco_hw_params,
59 +};
60 +
61 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_dai[] = {
62 +{
63 + .name = "DionAudio LOCO",
64 + .stream_name = "DionAudio LOCO DAC-AMP",
65 + .cpu_dai_name = "bcm2708-i2s.0",
66 + .codec_dai_name = "pcm5102a-hifi",
67 + .platform_name = "bcm2708-i2s.0",
68 + .codec_name = "pcm5102a-codec",
69 + .dai_fmt = SND_SOC_DAIFMT_I2S |
70 + SND_SOC_DAIFMT_NB_NF |
71 + SND_SOC_DAIFMT_CBS_CFS,
72 + .ops = &snd_rpi_dionaudio_loco_ops,
73 +},
74 +};
75 +
76 +/* audio machine driver */
77 +static struct snd_soc_card snd_rpi_dionaudio_loco = {
78 + .name = "snd_rpi_dionaudio_loco",
79 + .dai_link = snd_rpi_dionaudio_loco_dai,
80 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_dai),
81 +};
82 +
83 +static int snd_rpi_dionaudio_loco_probe(struct platform_device *pdev)
84 +{
85 + struct device_node *np;
86 + int ret = 0;
87 +
88 + snd_rpi_dionaudio_loco.dev = &pdev->dev;
89 +
90 + np = pdev->dev.of_node;
91 + if (np) {
92 + struct snd_soc_dai_link *dai = &snd_rpi_dionaudio_loco_dai[0];
93 + struct device_node *i2s_np;
94 +
95 + i2s_np = of_parse_phandle(np, "i2s-controller", 0);
96 + if (i2s_np) {
97 + dai->cpu_dai_name = NULL;
98 + dai->cpu_of_node = i2s_np;
99 + dai->platform_name = NULL;
100 + dai->platform_of_node = i2s_np;
101 + }
102 + }
103 +
104 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_dionaudio_loco);
105 + if (ret && ret != -EPROBE_DEFER)
106 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
107 + ret);
108 +
109 + return ret;
110 +}
111 +
112 +static const struct of_device_id snd_rpi_dionaudio_loco_of_match[] = {
113 + { .compatible = "dionaudio,loco-pcm5242-tpa3118", },
114 + { /* sentinel */ },
115 +};
116 +MODULE_DEVICE_TABLE(of, snd_rpi_dionaudio_loco_of_match);
117 +
118 +static struct platform_driver snd_rpi_dionaudio_loco_driver = {
119 + .driver = {
120 + .name = "snd-dionaudio-loco",
121 + .owner = THIS_MODULE,
122 + .of_match_table = snd_rpi_dionaudio_loco_of_match,
123 + },
124 + .probe = snd_rpi_dionaudio_loco_probe,
125 +};
126 +
127 +module_platform_driver(snd_rpi_dionaudio_loco_driver);
128 +
129 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
130 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO");
131 +MODULE_LICENSE("GPL v2");