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