bcm27xx: add linux 5.4 support
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0063-Add-driver-for-rpi-proto.patch
1 From b3cf65c5d12ff3bd52843a35dc912a705371d5b6 Mon Sep 17 00:00:00 2001
2 From: Waldemar Brodkorb <wbrodkorb@conet.de>
3 Date: Wed, 25 Mar 2015 09:26:17 +0100
4 Subject: [PATCH] Add driver for rpi-proto
5
6 Forward port of 3.10.x driver from https://github.com/koalo
7 We are using a custom board and would like to use rpi 3.18.x
8 kernel. Patch works fine for our embedded system.
9
10 URL to the audio chip:
11 http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/
12
13 Playback tested with devicetree enabled.
14
15 Signed-off-by: Waldemar Brodkorb <wbrodkorb@conet.de>
16
17 ASoC: rpi-proto: use modern dai_link style
18
19 Signed-off-by: Hui Wang <hui.wang@canonical.com>
20 ---
21 sound/soc/bcm/rpi-proto.c | 147 ++++++++++++++++++++++++++++++++++++++
22 1 file changed, 147 insertions(+)
23 create mode 100644 sound/soc/bcm/rpi-proto.c
24
25 --- /dev/null
26 +++ b/sound/soc/bcm/rpi-proto.c
27 @@ -0,0 +1,147 @@
28 +/*
29 + * ASoC driver for PROTO AudioCODEC (with a WM8731)
30 + * connected to a Raspberry Pi
31 + *
32 + * Author: Florian Meier, <koalo@koalo.de>
33 + * Copyright 2013
34 + *
35 + * This program is free software; you can redistribute it and/or modify
36 + * it under the terms of the GNU General Public License version 2 as
37 + * published by the Free Software Foundation.
38 + */
39 +
40 +#include <linux/module.h>
41 +#include <linux/platform_device.h>
42 +
43 +#include <sound/core.h>
44 +#include <sound/pcm.h>
45 +#include <sound/soc.h>
46 +#include <sound/jack.h>
47 +
48 +#include "../codecs/wm8731.h"
49 +
50 +static const unsigned int wm8731_rates_12288000[] = {
51 + 8000, 32000, 48000, 96000,
52 +};
53 +
54 +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
55 + .list = wm8731_rates_12288000,
56 + .count = ARRAY_SIZE(wm8731_rates_12288000),
57 +};
58 +
59 +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
60 +{
61 + /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
62 + snd_pcm_hw_constraint_list(substream->runtime, 0,
63 + SNDRV_PCM_HW_PARAM_RATE,
64 + &wm8731_constraints_12288000);
65 + return 0;
66 +}
67 +
68 +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
69 + struct snd_pcm_hw_params *params)
70 +{
71 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
72 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
73 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
74 + int sysclk = 12288000; /* This is fixed on this board */
75 +
76 + /* Set proto bclk */
77 + int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
78 + if (ret < 0){
79 + dev_err(rtd->card->dev,
80 + "Failed to set BCLK ratio %d\n", ret);
81 + return ret;
82 + }
83 +
84 + /* Set proto sysclk */
85 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
86 + sysclk, SND_SOC_CLOCK_IN);
87 + if (ret < 0) {
88 + dev_err(rtd->card->dev,
89 + "Failed to set WM8731 SYSCLK: %d\n", ret);
90 + return ret;
91 + }
92 +
93 + return 0;
94 +}
95 +
96 +/* machine stream operations */
97 +static struct snd_soc_ops snd_rpi_proto_ops = {
98 + .startup = snd_rpi_proto_startup,
99 + .hw_params = snd_rpi_proto_hw_params,
100 +};
101 +
102 +SND_SOC_DAILINK_DEFS(rpi_proto,
103 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
104 + DAILINK_COMP_ARRAY(COMP_CODEC("wm8731.1-001a", "wm8731-hifi")),
105 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
106 +
107 +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
108 +{
109 + .name = "WM8731",
110 + .stream_name = "WM8731 HiFi",
111 + .dai_fmt = SND_SOC_DAIFMT_I2S
112 + | SND_SOC_DAIFMT_NB_NF
113 + | SND_SOC_DAIFMT_CBM_CFM,
114 + .ops = &snd_rpi_proto_ops,
115 + SND_SOC_DAILINK_REG(rpi_proto),
116 +},
117 +};
118 +
119 +/* audio machine driver */
120 +static struct snd_soc_card snd_rpi_proto = {
121 + .name = "snd_rpi_proto",
122 + .owner = THIS_MODULE,
123 + .dai_link = snd_rpi_proto_dai,
124 + .num_links = ARRAY_SIZE(snd_rpi_proto_dai),
125 +};
126 +
127 +static int snd_rpi_proto_probe(struct platform_device *pdev)
128 +{
129 + int ret = 0;
130 +
131 + snd_rpi_proto.dev = &pdev->dev;
132 +
133 + if (pdev->dev.of_node) {
134 + struct device_node *i2s_node;
135 + struct snd_soc_dai_link *dai = &snd_rpi_proto_dai[0];
136 + i2s_node = of_parse_phandle(pdev->dev.of_node,
137 + "i2s-controller", 0);
138 +
139 + if (i2s_node) {
140 + dai->cpus->dai_name = NULL;
141 + dai->cpus->of_node = i2s_node;
142 + dai->platforms->name = NULL;
143 + dai->platforms->of_node = i2s_node;
144 + }
145 + }
146 +
147 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_proto);
148 + if (ret && ret != -EPROBE_DEFER)
149 + dev_err(&pdev->dev,
150 + "snd_soc_register_card() failed: %d\n", ret);
151 +
152 + return ret;
153 +}
154 +
155 +static const struct of_device_id snd_rpi_proto_of_match[] = {
156 + { .compatible = "rpi,rpi-proto", },
157 + {},
158 +};
159 +MODULE_DEVICE_TABLE(of, snd_rpi_proto_of_match);
160 +
161 +static struct platform_driver snd_rpi_proto_driver = {
162 + .driver = {
163 + .name = "snd-rpi-proto",
164 + .owner = THIS_MODULE,
165 + .of_match_table = snd_rpi_proto_of_match,
166 + },
167 + .probe = snd_rpi_proto_probe,
168 +};
169 +
170 +module_platform_driver(snd_rpi_proto_driver);
171 +
172 +MODULE_AUTHOR("Florian Meier");
173 +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
174 +MODULE_LICENSE("GPL");