bcm27xx: switch to 5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.10 / 950-0467-Added-PiFi-Mini-to-rpi-simple-soundcard.c.patch
1 From 4951e0d22b58566678a16d53bf06851e1b63eeff Mon Sep 17 00:00:00 2001
2 From: David Knell <david.knell@gmail.com>
3 Date: Mon, 8 Feb 2021 03:35:15 +0000
4 Subject: [PATCH] Added PiFi-Mini to rpi-simple-soundcard.c
5
6 Signed-off-by: David Knell <david.knell@gmail.com>
7 ---
8 sound/soc/bcm/rpi-simple-soundcard.c | 94 +++++++++++++++++++++++++---
9 1 file changed, 87 insertions(+), 7 deletions(-)
10
11 --- a/sound/soc/bcm/rpi-simple-soundcard.c
12 +++ b/sound/soc/bcm/rpi-simple-soundcard.c
13 @@ -32,6 +32,7 @@
14
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 +#include <linux/gpio/consumer.h>
18
19 #include <sound/core.h>
20 #include <sound/pcm.h>
21 @@ -45,6 +46,13 @@ struct snd_rpi_simple_drvdata {
22 unsigned int fixed_bclk_ratio;
23 };
24
25 +static struct snd_soc_card snd_rpi_simple = {
26 + .driver_name = "RPi-simple",
27 + .owner = THIS_MODULE,
28 + .dai_link = NULL,
29 + .num_links = 1, /* Only a single DAI supported at the moment */
30 +};
31 +
32 static int snd_rpi_simple_init(struct snd_soc_pcm_runtime *rtd)
33 {
34 struct snd_rpi_simple_drvdata *drvdata =
35 @@ -58,6 +66,60 @@ static int snd_rpi_simple_init(struct sn
36 return 0;
37 }
38
39 +static int pifi_mini_210_init(struct snd_soc_pcm_runtime *rtd)
40 +{
41 + struct snd_soc_component *dac;
42 + struct gpio_desc *pdn_gpio, *rst_gpio;
43 + struct snd_soc_dai *codec_dai;
44 + int ret;
45 +
46 + snd_rpi_simple_init(rtd);
47 + codec_dai = asoc_rtd_to_codec(rtd, 0);
48 +
49 + dac = codec_dai[0].component;
50 +
51 + pdn_gpio = devm_gpiod_get_optional(snd_rpi_simple.dev, "pdn",
52 + GPIOD_OUT_LOW);
53 + if (IS_ERR(pdn_gpio)) {
54 + ret = PTR_ERR(pdn_gpio);
55 + dev_err(snd_rpi_simple.dev, "failed to get pdn gpio: %d\n", ret);
56 + return ret;
57 + }
58 +
59 + rst_gpio = devm_gpiod_get_optional(snd_rpi_simple.dev, "rst",
60 + GPIOD_OUT_LOW);
61 + if (IS_ERR(rst_gpio)) {
62 + ret = PTR_ERR(rst_gpio);
63 + dev_err(snd_rpi_simple.dev, "failed to get rst gpio: %d\n", ret);
64 + return ret;
65 + }
66 +
67 + // Set up cards - pulse power down and reset first, then
68 + // set up according to datasheet
69 + gpiod_set_value_cansleep(pdn_gpio, 1);
70 + gpiod_set_value_cansleep(rst_gpio, 1);
71 + usleep_range(1000, 10000);
72 + gpiod_set_value_cansleep(pdn_gpio, 0);
73 + usleep_range(20000, 30000);
74 + gpiod_set_value_cansleep(rst_gpio, 0);
75 + usleep_range(20000, 30000);
76 +
77 + // Oscillator trim
78 + snd_soc_component_write(dac, 0x1b, 0);
79 + usleep_range(60000, 80000);
80 +
81 + // MCLK at 64fs, sample rate 44.1 or 48kHz
82 + snd_soc_component_write(dac, 0x00, 0x60);
83 +
84 + // Set up for BTL - AD/BD mode - AD is 0x00107772, BD is 0x00987772
85 + snd_soc_component_write(dac, 0x20, 0x00107772);
86 +
87 + // End mute
88 + snd_soc_component_write(dac, 0x05, 0x00);
89 +
90 + return 0;
91 +}
92 +
93 static int snd_rpi_simple_hw_params(struct snd_pcm_substream *substream,
94 struct snd_pcm_hw_params *params)
95 {
96 @@ -255,6 +317,29 @@ static struct snd_rpi_simple_drvdata drv
97 .fixed_bclk_ratio = 64,
98 };
99
100 +SND_SOC_DAILINK_DEFS(pifi_mini_210,
101 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
102 + DAILINK_COMP_ARRAY(COMP_CODEC("tas571x.1-001a", "tas571x-hifi")),
103 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
104 +
105 +static struct snd_soc_dai_link snd_pifi_mini_210_dai[] = {
106 + {
107 + .name = "PiFi Mini 210",
108 + .stream_name = "PiFi Mini 210 HiFi",
109 + .init = pifi_mini_210_init,
110 + .dai_fmt = SND_SOC_DAIFMT_I2S |
111 + SND_SOC_DAIFMT_NB_NF |
112 + SND_SOC_DAIFMT_CBS_CFS,
113 + SND_SOC_DAILINK_REG(pifi_mini_210),
114 + },
115 +};
116 +
117 +static struct snd_rpi_simple_drvdata drvdata_pifi_mini_210 = {
118 + .card_name = "snd_pifi_mini_210",
119 + .dai = snd_pifi_mini_210_dai,
120 + .fixed_bclk_ratio = 64,
121 +};
122 +
123 static const struct of_device_id snd_rpi_simple_of_match[] = {
124 { .compatible = "adi,adau1977-adc",
125 .data = (void *) &drvdata_adau1977 },
126 @@ -269,16 +354,11 @@ static const struct of_device_id snd_rpi
127 { .compatible = "rpi,rpi-dac", &drvdata_rpi_dac},
128 { .compatible = "merus,merus-amp",
129 .data = (void *) &drvdata_merus_amp },
130 + { .compatible = "pifi,pifi-mini-210",
131 + .data = (void *) &drvdata_pifi_mini_210 },
132 {},
133 };
134
135 -static struct snd_soc_card snd_rpi_simple = {
136 - .driver_name = "RPi-simple",
137 - .owner = THIS_MODULE,
138 - .dai_link = NULL,
139 - .num_links = 1, /* Only a single DAI supported at the moment */
140 -};
141 -
142 static int snd_rpi_simple_probe(struct platform_device *pdev)
143 {
144 int ret = 0;