OpenWrt – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | From 87d450d98ef1f69dd6f5255c3b7e665c130935ea Mon Sep 17 00:00:00 2001 |
2 | From: allocom <sparky-dev@allo.com> |
||
3 | Date: Thu, 19 Apr 2018 12:12:26 +0530 |
||
4 | Subject: [PATCH 281/454] Drivers for Allo Katana DAC |
||
5 | |||
6 | --- |
||
7 | arch/arm/boot/dts/overlays/Makefile | 1 + |
||
8 | arch/arm/boot/dts/overlays/README | 6 + |
||
9 | .../allo-katana-dac-audio-overlay.dts | 46 +++ |
||
10 | arch/arm/configs/bcm2709_defconfig | 1 + |
||
11 | arch/arm/configs/bcmrpi_defconfig | 1 + |
||
12 | sound/soc/bcm/Kconfig | 7 + |
||
13 | sound/soc/bcm/Makefile | 2 + |
||
14 | sound/soc/bcm/allo-katana-dac.c | 105 ++++++ |
||
15 | sound/soc/codecs/Kconfig | 10 + |
||
16 | sound/soc/codecs/Makefile | 4 + |
||
17 | sound/soc/codecs/sabre-ess-i2c.c | 69 ++++ |
||
18 | sound/soc/codecs/sabre-ess.c | 300 ++++++++++++++++++ |
||
19 | sound/soc/codecs/sabre-ess.h | 62 ++++ |
||
20 | 13 files changed, 614 insertions(+) |
||
21 | create mode 100644 arch/arm/boot/dts/overlays/allo-katana-dac-audio-overlay.dts |
||
22 | create mode 100644 sound/soc/bcm/allo-katana-dac.c |
||
23 | create mode 100644 sound/soc/codecs/sabre-ess-i2c.c |
||
24 | create mode 100644 sound/soc/codecs/sabre-ess.c |
||
25 | create mode 100644 sound/soc/codecs/sabre-ess.h |
||
26 | |||
27 | --- a/arch/arm/boot/dts/overlays/Makefile |
||
28 | +++ b/arch/arm/boot/dts/overlays/Makefile |
||
29 | @@ -9,6 +9,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \ |
||
30 | akkordion-iqdacplus.dtbo \ |
||
31 | allo-boss-dac-pcm512x-audio.dtbo \ |
||
32 | allo-digione.dtbo \ |
||
33 | + allo-katana-dac-audio.dtbo \ |
||
34 | allo-piano-dac-pcm512x-audio.dtbo \ |
||
35 | allo-piano-dac-plus-pcm512x-audio.dtbo \ |
||
36 | applepi-dac.dtbo \ |
||
37 | --- a/arch/arm/boot/dts/overlays/README |
||
38 | +++ b/arch/arm/boot/dts/overlays/README |
||
39 | @@ -317,6 +317,12 @@ Load: dtoverlay=allo-digione |
||
40 | Params: <None> |
||
41 | |||
42 | |||
43 | +Name: allo-katana |
||
44 | +Info: Configures the Allo Katana audio card |
||
45 | +Load: dtoverlay=allo-katana-dac-audio |
||
46 | +Params: <None> |
||
47 | + |
||
48 | + |
||
49 | Name: allo-piano-dac-pcm512x-audio |
||
50 | Info: Configures the Allo Piano DAC (2.0/2.1) audio cards. |
||
51 | (NB. This initial support is for 2.0 channel audio ONLY! ie. stereo. |
||
52 | --- /dev/null |
||
53 | +++ b/arch/arm/boot/dts/overlays/allo-katana-dac-audio-overlay.dts |
||
54 | @@ -0,0 +1,46 @@ |
||
55 | +/* |
||
56 | + * Definitions for Allo Katana DAC boards |
||
57 | + * |
||
58 | + * NB. The Katana DAC board contains SABER DAC. |
||
59 | + */ |
||
60 | + |
||
61 | +/dts-v1/; |
||
62 | +/plugin/; |
||
63 | + |
||
64 | +/ { |
||
65 | + compatible = "brcm,bcm2708"; |
||
66 | + |
||
67 | + fragment@0 { |
||
68 | + target = <&i2s>; |
||
69 | + __overlay__ { |
||
70 | + status = "okay"; |
||
71 | + }; |
||
72 | + }; |
||
73 | + |
||
74 | + fragment@1 { |
||
75 | + target = <&i2c1>; |
||
76 | + __overlay__ { |
||
77 | + #address-cells = <1>; |
||
78 | + #size-cells = <0>; |
||
79 | + status = "okay"; |
||
80 | + |
||
81 | + sabre-ess@30 { |
||
82 | + #sound-dai-cells = <0>; |
||
83 | + compatible = "saber,sabre-ess"; |
||
84 | + reg = <0x30>; |
||
85 | + status = "okay"; |
||
86 | + }; |
||
87 | + }; |
||
88 | + }; |
||
89 | + |
||
90 | + fragment@2 { |
||
91 | + target = <&sound>; |
||
92 | + katana_dac: __overlay__ { |
||
93 | + compatible = "allo,katana-dac"; |
||
94 | + i2s-controller = <&i2s>; |
||
95 | + status = "okay"; |
||
96 | + }; |
||
97 | + }; |
||
98 | + |
||
99 | +}; |
||
100 | + |
||
101 | --- a/arch/arm/configs/bcm2709_defconfig |
||
102 | +++ b/arch/arm/configs/bcm2709_defconfig |
||
103 | @@ -894,6 +894,7 @@ CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC=m |
||
104 | CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS=m |
||
105 | CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC=m |
||
106 | CONFIG_SND_BCM2708_SOC_ALLO_DIGIONE=m |
||
107 | +CONFIG_SND_BCM2708_SOC_ALLO_KATANA_DAC=m |
||
108 | CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO=m |
||
109 | CONFIG_SND_PISOUND=m |
||
110 | CONFIG_SND_SOC_ADAU1701=m |
||
111 | --- a/arch/arm/configs/bcmrpi_defconfig |
||
112 | +++ b/arch/arm/configs/bcmrpi_defconfig |
||
113 | @@ -887,6 +887,7 @@ CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC=m |
||
114 | CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS=m |
||
115 | CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC=m |
||
116 | CONFIG_SND_BCM2708_SOC_ALLO_DIGIONE=m |
||
117 | +CONFIG_SND_BCM2708_SOC_ALLO_KATANA_DAC=m |
||
118 | CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO=m |
||
119 | CONFIG_SND_PISOUND=m |
||
120 | CONFIG_SND_SOC_ADAU1701=m |
||
121 | --- a/sound/soc/bcm/Kconfig |
||
122 | +++ b/sound/soc/bcm/Kconfig |
||
123 | @@ -175,6 +175,13 @@ config SND_BCM2708_SOC_ALLO_DIGIONE |
||
124 | help |
||
125 | Say Y or M if you want to add support for Allo DigiOne. |
||
126 | |||
127 | +config SND_BCM2708_SOC_ALLO_KATANA_DAC |
||
128 | + tristate "Support for Allo Katana DAC" |
||
129 | + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S |
||
130 | + select SND_SOC_SABRE_ESS_I2C |
||
131 | + help |
||
132 | + Say Y or M if you want to add support for Allo Katana DAC. |
||
133 | + |
||
134 | config SND_BCM2708_SOC_FE_PI_AUDIO |
||
135 | tristate "Support for Fe-Pi-Audio" |
||
136 | depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S |
||
137 | --- a/sound/soc/bcm/Makefile |
||
138 | +++ b/sound/soc/bcm/Makefile |
||
139 | @@ -34,6 +34,7 @@ snd-soc-allo-boss-dac-objs := allo-boss- |
||
140 | snd-soc-allo-piano-dac-objs := allo-piano-dac.o |
||
141 | snd-soc-allo-piano-dac-plus-objs := allo-piano-dac-plus.o |
||
142 | snd-soc-allo-digione-objs := allo-digione.o |
||
143 | +snd-soc-allo-katana-dac-objs := allo-katana-dac.o |
||
144 | snd-soc-pisound-objs := pisound.o |
||
145 | snd-soc-fe-pi-audio-objs := fe-pi-audio.o |
||
146 | |||
147 | @@ -60,5 +61,6 @@ obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_D |
||
148 | obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o |
||
149 | obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS) += snd-soc-allo-piano-dac-plus.o |
||
150 | obj-$(CONFIG_SND_BCM2708_SOC_ALLO_DIGIONE) += snd-soc-allo-digione.o |
||
151 | +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_KATANA_DAC) += snd-soc-allo-katana-dac.o |
||
152 | obj-$(CONFIG_SND_PISOUND) += snd-soc-pisound.o |
||
153 | obj-$(CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO) += snd-soc-fe-pi-audio.o |
||
154 | --- /dev/null |
||
155 | +++ b/sound/soc/bcm/allo-katana-dac.c |
||
156 | @@ -0,0 +1,105 @@ |
||
157 | +/* |
||
158 | + * ASoC Driver for KATANA DAC |
||
159 | + * |
||
160 | + * Author: Jaikumar <jaikumar@cem-solutions.net> |
||
161 | + * Copyright 2018 |
||
162 | + * |
||
163 | + * This program is free software; you can redistribute it and/or |
||
164 | + * modify it under the terms of the GNU General Public License |
||
165 | + * version 2 as published by the Free Software Foundation. |
||
166 | + * |
||
167 | + * This program is distributed in the hope that it will be useful, but |
||
168 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
||
169 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||
170 | + * General Public License for more details. |
||
171 | + */ |
||
172 | + |
||
173 | +#include <linux/module.h> |
||
174 | +#include <linux/platform_device.h> |
||
175 | + |
||
176 | +#include <sound/core.h> |
||
177 | +#include <sound/pcm.h> |
||
178 | +#include <sound/pcm_params.h> |
||
179 | +#include <sound/soc.h> |
||
180 | + |
||
181 | +static struct snd_soc_dai_link snd_allo_katana_dac_dai[] = { |
||
182 | +{ |
||
183 | + .name = "KATANA DAC", |
||
184 | + //.stream_name = "KATANA DAC HiFi [Master]", |
||
185 | + .stream_name = "KATANA DAC", |
||
186 | + .cpu_dai_name = "bcm2708-i2s.0", |
||
187 | + //.codec_dai_name = "es9038q2m-hifi", |
||
188 | + .codec_dai_name = "sabre-ess", |
||
189 | + .platform_name = "bcm2708-i2s.0", |
||
190 | + //.codec_name = "es9038q2m.1-0030", |
||
191 | + .codec_name = "sabre-ess.1-0030", |
||
192 | + .dai_fmt = SND_SOC_DAIFMT_I2S | |
||
193 | + SND_SOC_DAIFMT_NB_NF | |
||
194 | + SND_SOC_DAIFMT_CBM_CFM, |
||
195 | +}, |
||
196 | +}; |
||
197 | + |
||
198 | +/* audio machine driver */ |
||
199 | +static struct snd_soc_card snd_allo_katana_dac = { |
||
200 | + .name = "snd_allo_katana_dac", |
||
201 | + .owner = THIS_MODULE, |
||
202 | + .dai_link = snd_allo_katana_dac_dai, |
||
203 | + .num_links = ARRAY_SIZE(snd_allo_katana_dac_dai), |
||
204 | +}; |
||
205 | + |
||
206 | +static int snd_allo_katana_dac_probe(struct platform_device *pdev) |
||
207 | +{ |
||
208 | + int ret = 0; |
||
209 | + |
||
210 | + snd_allo_katana_dac.dev = &pdev->dev; |
||
211 | + |
||
212 | + if (pdev->dev.of_node) { |
||
213 | + struct device_node *i2s_node; |
||
214 | + struct snd_soc_dai_link *dai = &snd_allo_katana_dac_dai[0]; |
||
215 | + |
||
216 | + i2s_node = of_parse_phandle(pdev->dev.of_node, |
||
217 | + "i2s-controller", 0); |
||
218 | + |
||
219 | + if (i2s_node) { |
||
220 | + dai->cpu_dai_name = NULL; |
||
221 | + dai->cpu_of_node = i2s_node; |
||
222 | + dai->platform_name = NULL; |
||
223 | + dai->platform_of_node = i2s_node; |
||
224 | + } |
||
225 | + } |
||
226 | + |
||
227 | + ret = snd_soc_register_card(&snd_allo_katana_dac); |
||
228 | + if (ret && ret != -EPROBE_DEFER) |
||
229 | + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
||
230 | + ret); |
||
231 | + |
||
232 | + return ret; |
||
233 | +} |
||
234 | + |
||
235 | +static int snd_allo_katana_dac_remove(struct platform_device *pdev) |
||
236 | +{ |
||
237 | + return snd_soc_unregister_card(&snd_allo_katana_dac); |
||
238 | +} |
||
239 | + |
||
240 | +static const struct of_device_id snd_allo_katana_dac_of_match[] = { |
||
241 | + { .compatible = "allo,katana-dac", }, |
||
242 | + {}, |
||
243 | +}; |
||
244 | +MODULE_DEVICE_TABLE(of, snd_allo_katana_dac_of_match); |
||
245 | + |
||
246 | +static struct platform_driver snd_allo_katana_dac_driver = { |
||
247 | + .driver = { |
||
248 | + .name = "snd-katana-dac", |
||
249 | + .owner = THIS_MODULE, |
||
250 | + .of_match_table = snd_allo_katana_dac_of_match, |
||
251 | + }, |
||
252 | + .probe = snd_allo_katana_dac_probe, |
||
253 | + .remove = snd_allo_katana_dac_remove, |
||
254 | +}; |
||
255 | + |
||
256 | +module_platform_driver(snd_allo_katana_dac_driver); |
||
257 | + |
||
258 | +MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>"); |
||
259 | +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Katana DAC"); |
||
260 | +MODULE_LICENSE("GPL v2"); |
||
261 | + |
||
262 | --- a/sound/soc/codecs/Kconfig |
||
263 | +++ b/sound/soc/codecs/Kconfig |
||
264 | @@ -77,6 +77,7 @@ config SND_SOC_ALL_CODECS |
||
265 | select SND_SOC_ES8328_SPI if SPI_MASTER |
||
266 | select SND_SOC_ES8328_I2C if I2C |
||
267 | select SND_SOC_ES7134 |
||
268 | + select SND_SOC_SABRE_ESS_I2C if I2C |
||
269 | select SND_SOC_GTM601 |
||
270 | select SND_SOC_HDAC_HDMI |
||
271 | select SND_SOC_ICS43432 |
||
272 | @@ -1186,4 +1187,13 @@ config SND_SOC_TPA6130A2 |
||
273 | tristate "Texas Instruments TPA6130A2 headphone amplifier" |
||
274 | depends on I2C |
||
275 | |||
276 | +config SND_SOC_SABRE_ESS |
||
277 | + tristate |
||
278 | + |
||
279 | +config SND_SOC_SABRE_ESS_I2C |
||
280 | + tristate "Sabre SABRE ESS CODEC - I2C" |
||
281 | + depends on I2C |
||
282 | + select SND_SOC_SABRE_ESS |
||
283 | + select REGMAP_I2C |
||
284 | + |
||
285 | endmenu |
||
286 | --- a/sound/soc/codecs/Makefile |
||
287 | +++ b/sound/soc/codecs/Makefile |
||
288 | @@ -71,6 +71,8 @@ snd-soc-es8316-objs := es8316.o |
||
289 | snd-soc-es8328-objs := es8328.o |
||
290 | snd-soc-es8328-i2c-objs := es8328-i2c.o |
||
291 | snd-soc-es8328-spi-objs := es8328-spi.o |
||
292 | +snd-soc-sabre-ess-objs := sabre-ess.o |
||
293 | +snd-soc-sabre-ess-i2c-objs := sabre-ess-i2c.o |
||
294 | snd-soc-gtm601-objs := gtm601.o |
||
295 | snd-soc-hdac-hdmi-objs := hdac_hdmi.o |
||
296 | snd-soc-ics43432-objs := ics43432.o |
||
297 | @@ -313,6 +315,8 @@ obj-$(CONFIG_SND_SOC_ES8316) += snd-s |
||
298 | obj-$(CONFIG_SND_SOC_ES8328) += snd-soc-es8328.o |
||
299 | obj-$(CONFIG_SND_SOC_ES8328_I2C)+= snd-soc-es8328-i2c.o |
||
300 | obj-$(CONFIG_SND_SOC_ES8328_SPI)+= snd-soc-es8328-spi.o |
||
301 | +obj-$(CONFIG_SND_SOC_SABRE_ESS) += snd-soc-sabre-ess.o |
||
302 | +obj-$(CONFIG_SND_SOC_SABRE_ESS_I2C) += snd-soc-sabre-ess-i2c.o |
||
303 | obj-$(CONFIG_SND_SOC_GTM601) += snd-soc-gtm601.o |
||
304 | obj-$(CONFIG_SND_SOC_HDAC_HDMI) += snd-soc-hdac-hdmi.o |
||
305 | obj-$(CONFIG_SND_SOC_ICS43432) += snd-soc-ics43432.o |
||
306 | --- /dev/null |
||
307 | +++ b/sound/soc/codecs/sabre-ess-i2c.c |
||
308 | @@ -0,0 +1,69 @@ |
||
309 | +/* |
||
310 | + * Driver for the SABRE ESS CODECs |
||
311 | + * |
||
312 | + * Author: Jaikumar <jaikumar@cem-solutions.net> |
||
313 | + * Copyright 2018 |
||
314 | + * |
||
315 | + * This program is free software; you can redistribute it and/or |
||
316 | + * modify it under the terms of the GNU General Public License |
||
317 | + * version 2 as published by the Free Software Foundation. |
||
318 | + * |
||
319 | + * This program is distributed in the hope that it will be useful, but |
||
320 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
||
321 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||
322 | + * General Public License for more details. |
||
323 | + */ |
||
324 | + |
||
325 | +#include <linux/init.h> |
||
326 | +#include <linux/module.h> |
||
327 | +#include <linux/i2c.h> |
||
328 | + |
||
329 | +#include "sabre-ess.h" |
||
330 | + |
||
331 | +static int sabre_ess_i2c_probe(struct i2c_client *i2c, |
||
332 | + const struct i2c_device_id *id) |
||
333 | +{ |
||
334 | + struct regmap *regmap; |
||
335 | + struct regmap_config config = sabre_ess_regmap; |
||
336 | + |
||
337 | + regmap = devm_regmap_init_i2c(i2c, &config); |
||
338 | + if (IS_ERR(regmap)) |
||
339 | + return PTR_ERR(regmap); |
||
340 | + |
||
341 | + return sabre_ess_probe(&i2c->dev, regmap); |
||
342 | +} |
||
343 | + |
||
344 | +static int sabre_ess_i2c_remove(struct i2c_client *i2c) |
||
345 | +{ |
||
346 | + sabre_ess_remove(&i2c->dev); |
||
347 | + return 0; |
||
348 | +} |
||
349 | + |
||
350 | +static const struct i2c_device_id sabre_ess_i2c_id[] = { |
||
351 | + { "sabre-ess", }, |
||
352 | + { } |
||
353 | +}; |
||
354 | +MODULE_DEVICE_TABLE(i2c, sabre_ess_i2c_id); |
||
355 | + |
||
356 | +static const struct of_device_id sabre_ess_of_match[] = { |
||
357 | + { .compatible = "saber,sabre-ess", }, |
||
358 | + { } |
||
359 | +}; |
||
360 | +MODULE_DEVICE_TABLE(of, sabre_ess_of_match); |
||
361 | + |
||
362 | +static struct i2c_driver sabre_ess_i2c_driver = { |
||
363 | + .probe = sabre_ess_i2c_probe, |
||
364 | + .remove = sabre_ess_i2c_remove, |
||
365 | + .id_table = sabre_ess_i2c_id, |
||
366 | + .driver = { |
||
367 | + .name = "sabre-ess", |
||
368 | + .of_match_table = sabre_ess_of_match, |
||
369 | + }, |
||
370 | +}; |
||
371 | + |
||
372 | +module_i2c_driver(sabre_ess_i2c_driver); |
||
373 | + |
||
374 | +MODULE_DESCRIPTION("ASoC SABRE ESS codec driver - I2C"); |
||
375 | +MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>"); |
||
376 | +MODULE_LICENSE("GPL v2"); |
||
377 | + |
||
378 | --- /dev/null |
||
379 | +++ b/sound/soc/codecs/sabre-ess.c |
||
380 | @@ -0,0 +1,300 @@ |
||
381 | +/* |
||
382 | + * Driver for the SABRE ESS CODEC |
||
383 | + * |
||
384 | + * Author: Jaikumar <jaikumar@cem-solutions.net> |
||
385 | + * Copyright 2018 |
||
386 | + * |
||
387 | + * This program is free software; you can redistribute it and/or |
||
388 | + * modify it under the terms of the GNU General Public License |
||
389 | + * version 2 as published by the Free Software Foundation. |
||
390 | + * |
||
391 | + * This program is distributed in the hope that it will be useful, but |
||
392 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
||
393 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||
394 | + * General Public License for more details. |
||
395 | + */ |
||
396 | + |
||
397 | + |
||
398 | +#include <linux/init.h> |
||
399 | +#include <linux/module.h> |
||
400 | +#include <linux/clk.h> |
||
401 | +#include <linux/kernel.h> |
||
402 | +#include <linux/pm_runtime.h> |
||
403 | +#include <linux/regmap.h> |
||
404 | +#include <linux/regulator/consumer.h> |
||
405 | +#include <linux/gcd.h> |
||
406 | +#include <sound/soc.h> |
||
407 | +#include <sound/soc-dapm.h> |
||
408 | +#include <sound/pcm_params.h> |
||
409 | +#include <sound/tlv.h> |
||
410 | + |
||
411 | +#include "sabre-ess.h" |
||
412 | + |
||
413 | +struct sabre_ess_priv { |
||
414 | + struct regmap *regmap; |
||
415 | + int fmt; |
||
416 | +}; |
||
417 | + |
||
418 | +static const struct reg_default sabre_ess_reg_defaults[] = { |
||
419 | + { SABRE_ESS_RESET, 0x00 }, |
||
420 | + { SABRE_ESS_VOLUME_1, 0xF0 }, |
||
421 | + { SABRE_ESS_VOLUME_2, 0xF0 }, |
||
422 | + { SABRE_ESS_MUTE, 0x00 }, |
||
423 | + { SABRE_ESS_DSP_PROGRAM, 0x04 }, |
||
424 | + { SABRE_ESS_DEEMPHASIS, 0x00 }, |
||
425 | + { SABRE_ESS_DOP, 0x01 }, |
||
426 | + { SABRE_ESS_FORMAT, 0xb4 }, |
||
427 | +}; |
||
428 | + |
||
429 | +static const char * const sabre_ess_dsp_program_texts[] = { |
||
430 | + "Linear Phase Fast Roll-off Filter", |
||
431 | + "Linear Phase Slow Roll-off Filter", |
||
432 | + "Minimum Phase Fast Roll-off Filter", |
||
433 | + "Minimum Phase Slow Roll-off Filter", |
||
434 | + "Apodizing Fast Roll-off Filter", |
||
435 | + "Corrected Minimum Phase Fast Roll-off Filter", |
||
436 | + "Brick Wall Filter", |
||
437 | +}; |
||
438 | + |
||
439 | +static const unsigned int sabre_ess_dsp_program_values[] = { |
||
440 | + 0, |
||
441 | + 1, |
||
442 | + 2, |
||
443 | + 3, |
||
444 | + 4, |
||
445 | + 6, |
||
446 | + 7, |
||
447 | +}; |
||
448 | + |
||
449 | +static SOC_VALUE_ENUM_SINGLE_DECL(sabre_ess_dsp_program, |
||
450 | + SABRE_ESS_DSP_PROGRAM, 0, 0x07, |
||
451 | + sabre_ess_dsp_program_texts, |
||
452 | + sabre_ess_dsp_program_values); |
||
453 | + |
||
454 | +static const char * const sabre_ess_deemphasis_texts[] = { |
||
455 | + "Bypass", |
||
456 | + "32kHz", |
||
457 | + "44.1kHz", |
||
458 | + "48kHz", |
||
459 | +}; |
||
460 | + |
||
461 | +static const unsigned int sabre_ess_deemphasis_values[] = { |
||
462 | + 0, |
||
463 | + 1, |
||
464 | + 2, |
||
465 | + 3, |
||
466 | +}; |
||
467 | + |
||
468 | +static SOC_VALUE_ENUM_SINGLE_DECL(sabre_ess_deemphasis, |
||
469 | + SABRE_ESS_DEEMPHASIS, 0, 0x03, |
||
470 | + sabre_ess_deemphasis_texts, |
||
471 | + sabre_ess_deemphasis_values); |
||
472 | + |
||
473 | +static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12700, 0); |
||
474 | + |
||
475 | +static const struct snd_kcontrol_new sabre_ess_controls[] = { |
||
476 | + SOC_DOUBLE_R_TLV("Master Playback Volume", SABRE_ESS_VOLUME_1, |
||
477 | + SABRE_ESS_VOLUME_2, 0, 255, 1, master_tlv), |
||
478 | + SOC_DOUBLE("Master Playback Switch", SABRE_ESS_MUTE, 0, 0, 1, 1), |
||
479 | + SOC_ENUM("DSP Program Route", sabre_ess_dsp_program), |
||
480 | + SOC_ENUM("Deemphasis Route", sabre_ess_deemphasis), |
||
481 | + SOC_SINGLE("DoP Playback Switch", SABRE_ESS_DOP, 0, 1, 1) |
||
482 | +}; |
||
483 | + |
||
484 | +static bool sabre_ess_readable_register(struct device *dev, unsigned int reg) |
||
485 | +{ |
||
486 | + switch (reg) { |
||
487 | + case SABRE_ESS_CHIP_ID_REG: |
||
488 | + return true; |
||
489 | + default: |
||
490 | + return reg < 0xff; |
||
491 | + } |
||
492 | +} |
||
493 | + |
||
494 | +static int sabre_ess_hw_params(struct snd_pcm_substream *substream, |
||
495 | + struct snd_pcm_hw_params *params, |
||
496 | + struct snd_soc_dai *dai) |
||
497 | +{ |
||
498 | + struct snd_soc_codec *codec = dai->codec; |
||
499 | + struct sabre_ess_priv *sabre_ess = snd_soc_codec_get_drvdata(codec); |
||
500 | + int fmt = 0; |
||
501 | + int ret; |
||
502 | + |
||
503 | + dev_dbg(codec->dev, "hw_params %u Hz, %u channels\n", |
||
504 | + params_rate(params), |
||
505 | + params_channels(params)); |
||
506 | + |
||
507 | + switch (sabre_ess->fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
||
508 | + case SND_SOC_DAIFMT_CBM_CFM: // master |
||
509 | + if (params_channels(params) == 2) |
||
510 | + fmt = SABRE_ESS_CHAN_STEREO; |
||
511 | + else |
||
512 | + fmt = SABRE_ESS_CHAN_MONO; |
||
513 | + |
||
514 | + switch (params_width(params)) { |
||
515 | + case 16: |
||
516 | + fmt |= SABRE_ESS_ALEN_16; |
||
517 | + break; |
||
518 | + case 24: |
||
519 | + fmt |= SABRE_ESS_ALEN_24; |
||
520 | + break; |
||
521 | + case 32: |
||
522 | + fmt |= SABRE_ESS_ALEN_32; |
||
523 | + break; |
||
524 | + default: |
||
525 | + dev_err(codec->dev, "Bad frame size: %d\n", |
||
526 | + params_width(params)); |
||
527 | + return -EINVAL; |
||
528 | + } |
||
529 | + |
||
530 | + switch (params_rate(params)) { |
||
531 | + case 44100: |
||
532 | + fmt |= SABRE_ESS_RATE_44100; |
||
533 | + break; |
||
534 | + case 48000: |
||
535 | + fmt |= SABRE_ESS_RATE_48000; |
||
536 | + break; |
||
537 | + case 88200: |
||
538 | + fmt |= SABRE_ESS_RATE_88200; |
||
539 | + break; |
||
540 | + case 96000: |
||
541 | + fmt |= SABRE_ESS_RATE_96000; |
||
542 | + break; |
||
543 | + case 176400: |
||
544 | + fmt |= SABRE_ESS_RATE_176400; |
||
545 | + break; |
||
546 | + case 192000: |
||
547 | + fmt |= SABRE_ESS_RATE_192000; |
||
548 | + break; |
||
549 | + case 352800: |
||
550 | + fmt |= SABRE_ESS_RATE_352800; |
||
551 | + break; |
||
552 | + case 384000: |
||
553 | + fmt |= SABRE_ESS_RATE_384000; |
||
554 | + break; |
||
555 | + default: |
||
556 | + dev_err(codec->dev, "Bad sample rate: %d\n", |
||
557 | + params_rate(params)); |
||
558 | + return -EINVAL; |
||
559 | + } |
||
560 | + |
||
561 | + ret = regmap_write(sabre_ess->regmap, SABRE_ESS_FORMAT, fmt); |
||
562 | + if (ret != 0) { |
||
563 | + dev_err(codec->dev, "Failed to set format: %d\n", ret); |
||
564 | + return ret; |
||
565 | + } |
||
566 | + break; |
||
567 | + |
||
568 | + default: |
||
569 | + return -EINVAL; |
||
570 | + } |
||
571 | + |
||
572 | + return 0; |
||
573 | +} |
||
574 | + |
||
575 | +static int sabre_ess_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
||
576 | +{ |
||
577 | + struct snd_soc_codec *codec = dai->codec; |
||
578 | + struct sabre_ess_priv *sabre_ess = snd_soc_codec_get_drvdata(codec); |
||
579 | + |
||
580 | + sabre_ess->fmt = fmt; |
||
581 | + |
||
582 | + return 0; |
||
583 | +} |
||
584 | + |
||
585 | +static const struct snd_soc_dai_ops sabre_ess_dai_ops = { |
||
586 | + .hw_params = sabre_ess_hw_params, |
||
587 | + .set_fmt = sabre_ess_set_fmt, |
||
588 | +}; |
||
589 | + |
||
590 | +static struct snd_soc_dai_driver sabre_ess_dai = { |
||
591 | + .name = "sabre-ess", |
||
592 | + .playback = { |
||
593 | + .stream_name = "Playback", |
||
594 | + .channels_min = 2, |
||
595 | + .channels_max = 2, |
||
596 | + .rates = SNDRV_PCM_RATE_CONTINUOUS, |
||
597 | + .rate_min = 44100, |
||
598 | + .rate_max = 384000, |
||
599 | + .formats = SNDRV_PCM_FMTBIT_S16_LE | |
||
600 | + SNDRV_PCM_FMTBIT_S32_LE |
||
601 | + }, |
||
602 | + .ops = &sabre_ess_dai_ops, |
||
603 | +}; |
||
604 | + |
||
605 | +static struct snd_soc_codec_driver sabre_ess_codec_driver = { |
||
606 | + .idle_bias_off = false, |
||
607 | + |
||
608 | + .component_driver = { |
||
609 | + .controls = sabre_ess_controls, |
||
610 | + .num_controls = ARRAY_SIZE(sabre_ess_controls), |
||
611 | + }, |
||
612 | +}; |
||
613 | + |
||
614 | +static const struct regmap_range_cfg sabre_ess_range = { |
||
615 | + .name = "Pages", .range_min = SABRE_ESS_VIRT_BASE, |
||
616 | + .range_max = SABRE_ESS_MAX_REGISTER, |
||
617 | + .selector_reg = SABRE_ESS_PAGE, |
||
618 | + .selector_mask = 0xff, |
||
619 | + .window_start = 0, .window_len = 0x100, |
||
620 | +}; |
||
621 | + |
||
622 | +const struct regmap_config sabre_ess_regmap = { |
||
623 | + .reg_bits = 8, |
||
624 | + .val_bits = 8, |
||
625 | + |
||
626 | + .ranges = &sabre_ess_range, |
||
627 | + .num_ranges = 1, |
||
628 | + |
||
629 | + .max_register = SABRE_ESS_MAX_REGISTER, |
||
630 | + .readable_reg = sabre_ess_readable_register, |
||
631 | + .reg_defaults = sabre_ess_reg_defaults, |
||
632 | + .num_reg_defaults = ARRAY_SIZE(sabre_ess_reg_defaults), |
||
633 | + .cache_type = REGCACHE_RBTREE, |
||
634 | +}; |
||
635 | +EXPORT_SYMBOL_GPL(sabre_ess_regmap); |
||
636 | + |
||
637 | +int sabre_ess_probe(struct device *dev, struct regmap *regmap) |
||
638 | +{ |
||
639 | + struct sabre_ess_priv *sabre_ess; |
||
640 | + unsigned int chip_id = 0; |
||
641 | + int ret; |
||
642 | + |
||
643 | + sabre_ess = devm_kzalloc(dev, sizeof(struct sabre_ess_priv), |
||
644 | + GFP_KERNEL); |
||
645 | + if (!sabre_ess) |
||
646 | + return -ENOMEM; |
||
647 | + |
||
648 | + dev_set_drvdata(dev, sabre_ess); |
||
649 | + sabre_ess->regmap = regmap; |
||
650 | + |
||
651 | + ret = regmap_read(regmap, SABRE_ESS_CHIP_ID_REG, &chip_id); |
||
652 | + if ((ret != 0) || (chip_id != SABRE_ESS_CHIP_ID)) { |
||
653 | + dev_err(dev, "Failed to read Chip or wrong Chip id: %d\n", ret); |
||
654 | + return ret; |
||
655 | + } |
||
656 | + regmap_update_bits(regmap, SABRE_ESS_RESET, 0x01, 0x01); |
||
657 | + msleep(10); |
||
658 | + |
||
659 | + ret = snd_soc_register_codec(dev, &sabre_ess_codec_driver, |
||
660 | + &sabre_ess_dai, 1); |
||
661 | + if (ret != 0) { |
||
662 | + dev_err(dev, "failed to register codec: %d\n", ret); |
||
663 | + return ret; |
||
664 | + } |
||
665 | + |
||
666 | + return 0; |
||
667 | +} |
||
668 | +EXPORT_SYMBOL_GPL(sabre_ess_probe); |
||
669 | + |
||
670 | +void sabre_ess_remove(struct device *dev) |
||
671 | +{ |
||
672 | + snd_soc_unregister_codec(dev); |
||
673 | + pm_runtime_disable(dev); |
||
674 | +} |
||
675 | +EXPORT_SYMBOL_GPL(sabre_ess_remove); |
||
676 | + |
||
677 | +MODULE_DESCRIPTION("ASoC SABRE ESS codec driver"); |
||
678 | +MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>"); |
||
679 | +MODULE_LICENSE("GPL v2"); |
||
680 | + |
||
681 | --- /dev/null |
||
682 | +++ b/sound/soc/codecs/sabre-ess.h |
||
683 | @@ -0,0 +1,62 @@ |
||
684 | +/* |
||
685 | + * Driver for the SABRE ESS CODEC |
||
686 | + * |
||
687 | + * Author: Jaikumar <jaikumar@cem-solutions.net> |
||
688 | + * Copyright 2018 |
||
689 | + * |
||
690 | + * This program is free software; you can redistribute it and/or |
||
691 | + * modify it under the terms of the GNU General Public License |
||
692 | + * version 2 as published by the Free Software Foundation. |
||
693 | + * |
||
694 | + * This program is distributed in the hope that it will be useful, but |
||
695 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
||
696 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||
697 | + * General Public License for more details. |
||
698 | + */ |
||
699 | + |
||
700 | +#ifndef _SND_SOC_SABRE_ESS_ |
||
701 | +#define _SND_SOC_SABRE_ESS_ |
||
702 | + |
||
703 | +#include <linux/pm.h> |
||
704 | +#include <linux/regmap.h> |
||
705 | + |
||
706 | +#define SABRE_ESS_CHIP_ID 0x30 |
||
707 | +#define SABRE_ESS_VIRT_BASE 0x100 |
||
708 | +#define SABRE_ESS_PAGE 0 |
||
709 | + |
||
710 | +#define SABRE_ESS_CHIP_ID_REG (SABRE_ESS_VIRT_BASE + 0) |
||
711 | +#define SABRE_ESS_RESET (SABRE_ESS_VIRT_BASE + 1) |
||
712 | +#define SABRE_ESS_VOLUME_1 (SABRE_ESS_VIRT_BASE + 2) |
||
713 | +#define SABRE_ESS_VOLUME_2 (SABRE_ESS_VIRT_BASE + 3) |
||
714 | +#define SABRE_ESS_MUTE (SABRE_ESS_VIRT_BASE + 4) |
||
715 | +#define SABRE_ESS_DSP_PROGRAM (SABRE_ESS_VIRT_BASE + 5) |
||
716 | +#define SABRE_ESS_DEEMPHASIS (SABRE_ESS_VIRT_BASE + 6) |
||
717 | +#define SABRE_ESS_DOP (SABRE_ESS_VIRT_BASE + 7) |
||
718 | +#define SABRE_ESS_FORMAT (SABRE_ESS_VIRT_BASE + 8) |
||
719 | +#define SABRE_ESS_COMMAND (SABRE_ESS_VIRT_BASE + 9) |
||
720 | +#define SABRE_ESS_MAX_REGISTER (SABRE_ESS_VIRT_BASE + 9) |
||
721 | + |
||
722 | +#define SABRE_ESS_FMT 0xff |
||
723 | +#define SABRE_ESS_CHAN_MONO 0x00 |
||
724 | +#define SABRE_ESS_CHAN_STEREO 0x80 |
||
725 | +#define SABRE_ESS_ALEN_16 0x10 |
||
726 | +#define SABRE_ESS_ALEN_24 0x20 |
||
727 | +#define SABRE_ESS_ALEN_32 0x30 |
||
728 | +#define SABRE_ESS_RATE_11025 0x01 |
||
729 | +#define SABRE_ESS_RATE_22050 0x02 |
||
730 | +#define SABRE_ESS_RATE_32000 0x03 |
||
731 | +#define SABRE_ESS_RATE_44100 0x04 |
||
732 | +#define SABRE_ESS_RATE_48000 0x05 |
||
733 | +#define SABRE_ESS_RATE_88200 0x06 |
||
734 | +#define SABRE_ESS_RATE_96000 0x07 |
||
735 | +#define SABRE_ESS_RATE_176400 0x08 |
||
736 | +#define SABRE_ESS_RATE_192000 0x09 |
||
737 | +#define SABRE_ESS_RATE_352800 0x0a |
||
738 | +#define SABRE_ESS_RATE_384000 0x0b |
||
739 | + |
||
740 | +extern const struct regmap_config sabre_ess_regmap; |
||
741 | + |
||
742 | +int sabre_ess_probe(struct device *dev, struct regmap *regmap); |
||
743 | +void sabre_ess_remove(struct device *dev); |
||
744 | + |
||
745 | +#endif /* _SND_SOC_SABRE_ESS_ */ |