brcm2708: add linux 4.19 support
[oweals/openwrt.git] / target / linux / brcm2708 / patches-4.19 / 950-0070-Add-driver-for-rpi-proto.patch
1 From 0a8842f908f015bd889e3c0cee5115db1c451990 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 070/703] 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  sound/soc/bcm/rpi-proto.c | 145 ++++++++++++++++++++++++++++++++++++++
18  1 file changed, 145 insertions(+)
19  create mode 100644 sound/soc/bcm/rpi-proto.c
20
21 --- /dev/null
22 +++ b/sound/soc/bcm/rpi-proto.c
23 @@ -0,0 +1,145 @@
24 +/*
25 + * ASoC driver for PROTO AudioCODEC (with a WM8731)
26 + * connected to a Raspberry Pi
27 + *
28 + * Author:      Florian Meier, <koalo@koalo.de>
29 + *           Copyright 2013
30 + *
31 + * This program is free software; you can redistribute it and/or modify
32 + * it under the terms of the GNU General Public License version 2 as
33 + * published by the Free Software Foundation.
34 + */
35 +
36 +#include <linux/module.h>
37 +#include <linux/platform_device.h>
38 +
39 +#include <sound/core.h>
40 +#include <sound/pcm.h>
41 +#include <sound/soc.h>
42 +#include <sound/jack.h>
43 +
44 +#include "../codecs/wm8731.h"
45 +
46 +static const unsigned int wm8731_rates_12288000[] = {
47 +       8000, 32000, 48000, 96000,
48 +};
49 +
50 +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
51 +       .list = wm8731_rates_12288000,
52 +       .count = ARRAY_SIZE(wm8731_rates_12288000),
53 +};
54 +
55 +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
56 +{
57 +       /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
58 +       snd_pcm_hw_constraint_list(substream->runtime, 0,
59 +                               SNDRV_PCM_HW_PARAM_RATE,
60 +                               &wm8731_constraints_12288000);
61 +       return 0;
62 +}
63 +
64 +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
65 +                                      struct snd_pcm_hw_params *params)
66 +{
67 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
68 +       struct snd_soc_dai *codec_dai = rtd->codec_dai;
69 +       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
70 +       int sysclk = 12288000; /* This is fixed on this board */
71 +
72 +       /* Set proto bclk */
73 +       int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
74 +       if (ret < 0){
75 +               dev_err(rtd->card->dev,
76 +                               "Failed to set BCLK ratio %d\n", ret);
77 +               return ret;
78 +       }
79 +
80 +       /* Set proto sysclk */
81 +       ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
82 +                       sysclk, SND_SOC_CLOCK_IN);
83 +       if (ret < 0) {
84 +               dev_err(rtd->card->dev,
85 +                               "Failed to set WM8731 SYSCLK: %d\n", ret);
86 +               return ret;
87 +       }
88 +
89 +       return 0;
90 +}
91 +
92 +/* machine stream operations */
93 +static struct snd_soc_ops snd_rpi_proto_ops = {
94 +       .startup = snd_rpi_proto_startup,
95 +       .hw_params = snd_rpi_proto_hw_params,
96 +};
97 +
98 +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
99 +{
100 +       .name           = "WM8731",
101 +       .stream_name    = "WM8731 HiFi",
102 +       .cpu_dai_name   = "bcm2708-i2s.0",
103 +       .codec_dai_name = "wm8731-hifi",
104 +       .platform_name  = "bcm2708-i2s.0",
105 +       .codec_name     = "wm8731.1-001a",
106 +       .dai_fmt        = SND_SOC_DAIFMT_I2S
107 +                               | SND_SOC_DAIFMT_NB_NF
108 +                               | SND_SOC_DAIFMT_CBM_CFM,
109 +       .ops            = &snd_rpi_proto_ops,
110 +},
111 +};
112 +
113 +/* audio machine driver */
114 +static struct snd_soc_card snd_rpi_proto = {
115 +       .name           = "snd_rpi_proto",
116 +       .owner          = THIS_MODULE,
117 +       .dai_link       = snd_rpi_proto_dai,
118 +       .num_links      = ARRAY_SIZE(snd_rpi_proto_dai),
119 +};
120 +
121 +static int snd_rpi_proto_probe(struct platform_device *pdev)
122 +{
123 +       int ret = 0;
124 +
125 +       snd_rpi_proto.dev = &pdev->dev;
126 +
127 +       if (pdev->dev.of_node) {
128 +               struct device_node *i2s_node;
129 +               struct snd_soc_dai_link *dai = &snd_rpi_proto_dai[0];
130 +               i2s_node = of_parse_phandle(pdev->dev.of_node,
131 +                                           "i2s-controller", 0);
132 +
133 +               if (i2s_node) {
134 +                       dai->cpu_dai_name = NULL;
135 +                       dai->cpu_of_node = i2s_node;
136 +                       dai->platform_name = NULL;
137 +                       dai->platform_of_node = i2s_node;
138 +               }
139 +       }
140 +
141 +       ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_proto);
142 +       if (ret && ret != -EPROBE_DEFER)
143 +               dev_err(&pdev->dev,
144 +                               "snd_soc_register_card() failed: %d\n", ret);
145 +
146 +       return ret;
147 +}
148 +
149 +static const struct of_device_id snd_rpi_proto_of_match[] = {
150 +       { .compatible = "rpi,rpi-proto", },
151 +       {},
152 +};
153 +MODULE_DEVICE_TABLE(of, snd_rpi_proto_of_match);
154 +
155 +static struct platform_driver snd_rpi_proto_driver = {
156 +       .driver = {
157 +               .name   = "snd-rpi-proto",
158 +               .owner  = THIS_MODULE,
159 +               .of_match_table = snd_rpi_proto_of_match,
160 +       },
161 +       .probe    = snd_rpi_proto_probe,
162 +};
163 +
164 +module_platform_driver(snd_rpi_proto_driver);
165 +
166 +MODULE_AUTHOR("Florian Meier");
167 +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
168 +MODULE_LICENSE("GPL");