brcm2708-gpu-fw: update to latest firmware
[openwrt/staging/dedeckeh.git] / target / linux / brcm2708 / patches-4.19 / 950-0357-Audiophonics-I-Sabre-9038Q2M-DAC-driver.patch
1 From c667b06f616d5dec68469ac73764abd5bcb1d694 Mon Sep 17 00:00:00 2001
2 From: FERHAT Nicolas <contact@audiophonics.fr>
3 Date: Fri, 5 Apr 2019 13:06:42 +0100
4 Subject: [PATCH] Audiophonics I-Sabre 9038Q2M DAC driver
5
6 Signed-off-by: Audiophonics <contact@audiophonics.fr>
7 ---
8 arch/arm/boot/dts/overlays/Makefile | 1 +
9 arch/arm/boot/dts/overlays/README | 6 +
10 .../boot/dts/overlays/i-sabre-q2m-overlay.dts | 39 ++
11 sound/soc/bcm/Kconfig | 7 +
12 sound/soc/bcm/Makefile | 2 +
13 sound/soc/bcm/i-sabre-q2m.c | 157 +++++++
14 sound/soc/codecs/Kconfig | 5 +
15 sound/soc/codecs/Makefile | 2 +
16 sound/soc/codecs/i-sabre-codec.c | 392 ++++++++++++++++++
17 sound/soc/codecs/i-sabre-codec.h | 42 ++
18 13 files changed, 656 insertions(+)
19 create mode 100644 arch/arm/boot/dts/overlays/i-sabre-q2m-overlay.dts
20 create mode 100644 sound/soc/bcm/i-sabre-q2m.c
21 create mode 100644 sound/soc/codecs/i-sabre-codec.c
22 create mode 100644 sound/soc/codecs/i-sabre-codec.h
23
24 --- a/arch/arm/boot/dts/overlays/Makefile
25 +++ b/arch/arm/boot/dts/overlays/Makefile
26 @@ -55,6 +55,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
27 hy28a.dtbo \
28 hy28b.dtbo \
29 hy28b-2017.dtbo \
30 + i-sabre-q2m.dtbo \
31 i2c-bcm2708.dtbo \
32 i2c-gpio.dtbo \
33 i2c-mux.dtbo \
34 --- a/arch/arm/boot/dts/overlays/README
35 +++ b/arch/arm/boot/dts/overlays/README
36 @@ -869,6 +869,12 @@ Params: speed Display
37 ledgpio GPIO used to control backlight
38
39
40 +Name: i-sabre-q2m
41 +Info: Configures the Audiophonics I-SABRE Q2M DAC
42 +Load: dtoverlay=i-sabre-q2m
43 +Params: <None>
44 +
45 +
46 Name: i2c-bcm2708
47 Info: Fall back to the i2c_bcm2708 driver for the i2c_arm bus.
48 Load: dtoverlay=i2c-bcm2708
49 --- /dev/null
50 +++ b/arch/arm/boot/dts/overlays/i-sabre-q2m-overlay.dts
51 @@ -0,0 +1,39 @@
52 +// Definitions for I-Sabre Q2M
53 +/dts-v1/;
54 +/plugin/;
55 +
56 +/ {
57 + compatible = "brcm,bcm2708";
58 +
59 + fragment@0 {
60 + target = <&sound>;
61 + frag0: __overlay__ {
62 + compatible = "audiophonics,i-sabre-q2m";
63 + i2s-controller = <&i2s>;
64 + status = "okay";
65 + };
66 + };
67 +
68 + fragment@1 {
69 + target = <&i2s>;
70 + __overlay__ {
71 + status = "okay";
72 + };
73 + };
74 +
75 + fragment@2 {
76 + target = <&i2c1>;
77 + __overlay__ {
78 + #address-cells = <1>;
79 + #size-cells = <0>;
80 + status = "okay";
81 +
82 + i-sabre-codec@48 {
83 + #sound-dai-cells = <0>;
84 + compatible = "audiophonics,i-sabre-codec";
85 + reg = <0x48>;
86 + status = "okay";
87 + };
88 + };
89 + };
90 +};
91 --- a/sound/soc/bcm/Kconfig
92 +++ b/sound/soc/bcm/Kconfig
93 @@ -123,6 +123,13 @@ config SND_BCM2708_SOC_IQAUDIO_DIGI
94 help
95 Say Y or M if you want to add support for IQAudIO Digital IO board.
96
97 +config SND_BCM2708_SOC_I_SABRE_Q2M
98 + tristate "Support for Audiophonics I-Sabre Q2M DAC"
99 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
100 + select SND_SOC_I_SABRE_CODEC
101 + help
102 + Say Y or M if you want to add support for Audiophonics I-SABRE Q2M DAC
103 +
104 config SND_BCM2708_SOC_ADAU1977_ADC
105 tristate "Support for ADAU1977 ADC"
106 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
107 --- a/sound/soc/bcm/Makefile
108 +++ b/sound/soc/bcm/Makefile
109 @@ -19,6 +19,7 @@ snd-soc-justboom-dac-objs := justboom-da
110 snd-soc-rpi-cirrus-objs := rpi-cirrus.o
111 snd-soc-rpi-proto-objs := rpi-proto.o
112 snd-soc-iqaudio-dac-objs := iqaudio-dac.o
113 + snd-soc-i-sabre-q2m-objs := i-sabre-q2m.o
114 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
115 snd-soc-audioinjector-octo-soundcard-objs := audioinjector-octo-soundcard.o
116 snd-soc-audiosense-pi-objs := audiosense-pi.o
117 @@ -42,6 +43,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DA
118 obj-$(CONFIG_SND_BCM2708_SOC_RPI_CIRRUS) += snd-soc-rpi-cirrus.o
119 obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
120 obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
121 + obj-$(CONFIG_SND_BCM2708_SOC_I_SABRE_Q2M) += snd-soc-i-sabre-q2m.o
122 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
123 obj-$(CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD) += snd-soc-audioinjector-octo-soundcard.o
124 obj-$(CONFIG_SND_AUDIOSENSE_PI) += snd-soc-audiosense-pi.o
125 --- /dev/null
126 +++ b/sound/soc/bcm/i-sabre-q2m.c
127 @@ -0,0 +1,157 @@
128 +/*
129 + * ASoC Driver for I-Sabre Q2M
130 + *
131 + * Author: Satoru Kawase
132 + * Modified by: Xiao Qingyong
133 + * Update kernel v4.18+ by : Audiophonics
134 + * Copyright 2018 Audiophonics
135 + *
136 + * This program is free software; you can redistribute it and/or
137 + * modify it under the terms of the GNU General Public License
138 + * version 2 as published by the Free Software Foundation.
139 + *
140 + * This program is distributed in the hope that it will be useful, but
141 + * WITHOUT ANY WARRANTY; without even the implied warranty of
142 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
143 + * General Public License for more details.
144 + */
145 +
146 +#include <linux/kernel.h>
147 +#include <linux/init.h>
148 +#include <linux/module.h>
149 +#include <linux/delay.h>
150 +#include <linux/fs.h>
151 +#include <asm/uaccess.h>
152 +#include <sound/core.h>
153 +#include <sound/soc.h>
154 +#include <sound/pcm.h>
155 +#include <sound/pcm_params.h>
156 +
157 +#include "../codecs/i-sabre-codec.h"
158 +
159 +
160 +static int snd_rpi_i_sabre_q2m_init(struct snd_soc_pcm_runtime *rtd)
161 +{
162 + struct snd_soc_component *component = rtd->codec_dai->component;
163 + unsigned int value;
164 +
165 + /* Device ID */
166 + value = snd_soc_component_read32(component, ISABRECODEC_REG_01);
167 + dev_info(component->card->dev, "Audiophonics Device ID : %02X\n", value);
168 +
169 + /* API revision */
170 + value = snd_soc_component_read32(component, ISABRECODEC_REG_02);
171 + dev_info(component->card->dev, "Audiophonics API revision : %02X\n", value);
172 +
173 + return 0;
174 +}
175 +
176 +static int snd_rpi_i_sabre_q2m_hw_params(
177 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
178 +{
179 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
180 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
181 + int bclk_ratio;
182 +
183 + bclk_ratio = snd_pcm_format_physical_width(
184 + params_format(params)) * params_channels(params);
185 + return snd_soc_dai_set_bclk_ratio(cpu_dai, bclk_ratio);
186 +}
187 +
188 +/* machine stream operations */
189 +static struct snd_soc_ops snd_rpi_i_sabre_q2m_ops = {
190 + .hw_params = snd_rpi_i_sabre_q2m_hw_params,
191 +};
192 +
193 +
194 +static struct snd_soc_dai_link snd_rpi_i_sabre_q2m_dai[] = {
195 + {
196 + .name = "I-Sabre Q2M",
197 + .stream_name = "I-Sabre Q2M DAC",
198 + .cpu_dai_name = "bcm2708-i2s.0",
199 + .codec_dai_name = "i-sabre-codec-dai",
200 + .platform_name = "bcm2708-i2s.0",
201 + .codec_name = "i-sabre-codec-i2c.1-0048",
202 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
203 + | SND_SOC_DAIFMT_CBS_CFS,
204 + .init = snd_rpi_i_sabre_q2m_init,
205 + .ops = &snd_rpi_i_sabre_q2m_ops,
206 + }
207 +};
208 +
209 +/* audio machine driver */
210 +static struct snd_soc_card snd_rpi_i_sabre_q2m = {
211 + .name = "I-Sabre Q2M DAC",
212 + .owner = THIS_MODULE,
213 + .dai_link = snd_rpi_i_sabre_q2m_dai,
214 + .num_links = ARRAY_SIZE(snd_rpi_i_sabre_q2m_dai)
215 +};
216 +
217 +
218 +static int snd_rpi_i_sabre_q2m_probe(struct platform_device *pdev)
219 +{
220 + int ret = 0;
221 +
222 + snd_rpi_i_sabre_q2m.dev = &pdev->dev;
223 + if (pdev->dev.of_node) {
224 + struct device_node *i2s_node;
225 + struct snd_soc_dai_link *dai;
226 +
227 + dai = &snd_rpi_i_sabre_q2m_dai[0];
228 + i2s_node = of_parse_phandle(pdev->dev.of_node,
229 + "i2s-controller", 0);
230 + if (i2s_node) {
231 + dai->cpu_dai_name = NULL;
232 + dai->cpu_of_node = i2s_node;
233 + dai->platform_name = NULL;
234 + dai->platform_of_node = i2s_node;
235 + } else {
236 + dev_err(&pdev->dev,
237 + "Property 'i2s-controller' missing or invalid\n");
238 + return (-EINVAL);
239 + }
240 +
241 + dai->name = "I-Sabre Q2M";
242 + dai->stream_name = "I-Sabre Q2M DAC";
243 + dai->dai_fmt = SND_SOC_DAIFMT_I2S
244 + | SND_SOC_DAIFMT_NB_NF
245 + | SND_SOC_DAIFMT_CBS_CFS;
246 + }
247 +
248 + /* Wait for registering codec driver */
249 + mdelay(50);
250 +
251 + ret = snd_soc_register_card(&snd_rpi_i_sabre_q2m);
252 + if (ret) {
253 + dev_err(&pdev->dev,
254 + "snd_soc_register_card() failed: %d\n", ret);
255 + }
256 +
257 + return ret;
258 +}
259 +
260 +static int snd_rpi_i_sabre_q2m_remove(struct platform_device *pdev)
261 +{
262 + return snd_soc_unregister_card(&snd_rpi_i_sabre_q2m);
263 +}
264 +
265 +static const struct of_device_id snd_rpi_i_sabre_q2m_of_match[] = {
266 + { .compatible = "audiophonics,i-sabre-q2m", },
267 + {}
268 +};
269 +MODULE_DEVICE_TABLE(of, snd_rpi_i_sabre_q2m_of_match);
270 +
271 +static struct platform_driver snd_rpi_i_sabre_q2m_driver = {
272 + .driver = {
273 + .name = "snd-rpi-i-sabre-q2m",
274 + .owner = THIS_MODULE,
275 + .of_match_table = snd_rpi_i_sabre_q2m_of_match,
276 + },
277 + .probe = snd_rpi_i_sabre_q2m_probe,
278 + .remove = snd_rpi_i_sabre_q2m_remove,
279 +};
280 +module_platform_driver(snd_rpi_i_sabre_q2m_driver);
281 +
282 +MODULE_DESCRIPTION("ASoC Driver for I-Sabre Q2M");
283 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
284 +MODULE_LICENSE("GPL");
285 --- a/sound/soc/codecs/Kconfig
286 +++ b/sound/soc/codecs/Kconfig
287 @@ -85,6 +85,7 @@ config SND_SOC_ALL_CODECS
288 select SND_SOC_ICS43432
289 select SND_SOC_INNO_RK3036
290 select SND_SOC_ISABELLE if I2C
291 + select SND_SOC_I_SABRE_CODEC if I2C
292 select SND_SOC_JZ4740_CODEC
293 select SND_SOC_LM4857 if I2C
294 select SND_SOC_LM49453 if I2C
295 @@ -1322,4 +1323,8 @@ config SND_SOC_TPA6130A2
296 tristate "Texas Instruments TPA6130A2 headphone amplifier"
297 depends on I2C
298
299 +config SND_SOC_I_SABRE_CODEC
300 + tristate "Audiophonics I-SABRE Codec"
301 + depends on I2C
302 +
303 endmenu
304 --- a/sound/soc/codecs/Makefile
305 +++ b/sound/soc/codecs/Makefile
306 @@ -81,6 +81,7 @@ snd-soc-hdac-hdmi-objs := hdac_hdmi.o
307 snd-soc-ics43432-objs := ics43432.o
308 snd-soc-inno-rk3036-objs := inno_rk3036.o
309 snd-soc-isabelle-objs := isabelle.o
310 +snd-soc-i-sabre-codec-objs := i-sabre-codec.o
311 snd-soc-jz4740-codec-objs := jz4740.o
312 snd-soc-l3-objs := l3.o
313 snd-soc-lm4857-objs := lm4857.o
314 @@ -343,6 +344,7 @@ obj-$(CONFIG_SND_SOC_HDAC_HDMI) += snd-s
315 obj-$(CONFIG_SND_SOC_ICS43432) += snd-soc-ics43432.o
316 obj-$(CONFIG_SND_SOC_INNO_RK3036) += snd-soc-inno-rk3036.o
317 obj-$(CONFIG_SND_SOC_ISABELLE) += snd-soc-isabelle.o
318 +obj-$(CONFIG_SND_SOC_I_SABRE_CODEC) += snd-soc-i-sabre-codec.o
319 obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o
320 obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
321 obj-$(CONFIG_SND_SOC_LM4857) += snd-soc-lm4857.o
322 --- /dev/null
323 +++ b/sound/soc/codecs/i-sabre-codec.c
324 @@ -0,0 +1,392 @@
325 +/*
326 + * Driver for I-Sabre Q2M
327 + *
328 + * Author: Satoru Kawase
329 + * Modified by: Xiao Qingyong
330 + * Modified by: JC BARBAUD (Mute)
331 + * Update kernel v4.18+ by : Audiophonics
332 + * Copyright 2018 Audiophonics
333 + *
334 + * This program is free software; you can redistribute it and/or
335 + * modify it under the terms of the GNU General Public License
336 + * version 2 as published by the Free Software Foundation.
337 + *
338 + * This program is distributed in the hope that it will be useful, but
339 + * WITHOUT ANY WARRANTY; without even the implied warranty of
340 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
341 + * General Public License for more details.
342 + */
343 +
344 +
345 +#include <linux/init.h>
346 +#include <linux/module.h>
347 +#include <linux/regmap.h>
348 +#include <linux/i2c.h>
349 +#include <sound/soc.h>
350 +#include <sound/pcm_params.h>
351 +#include <sound/tlv.h>
352 +
353 +#include "i-sabre-codec.h"
354 +
355 +
356 +/* I-Sabre Q2M Codec Private Data */
357 +struct i_sabre_codec_priv {
358 + struct regmap *regmap;
359 + unsigned int fmt;
360 +};
361 +
362 +
363 +/* I-Sabre Q2M Codec Default Register Value */
364 +static const struct reg_default i_sabre_codec_reg_defaults[] = {
365 + { ISABRECODEC_REG_10, 0x00 },
366 + { ISABRECODEC_REG_20, 0x00 },
367 + { ISABRECODEC_REG_21, 0x00 },
368 + { ISABRECODEC_REG_22, 0x00 },
369 + { ISABRECODEC_REG_24, 0x00 },
370 +};
371 +
372 +
373 +static bool i_sabre_codec_writeable(struct device *dev, unsigned int reg)
374 +{
375 + switch (reg) {
376 + case ISABRECODEC_REG_10:
377 + case ISABRECODEC_REG_20:
378 + case ISABRECODEC_REG_21:
379 + case ISABRECODEC_REG_22:
380 + case ISABRECODEC_REG_24:
381 + return true;
382 +
383 + default:
384 + return false;
385 + }
386 +}
387 +
388 +static bool i_sabre_codec_readable(struct device *dev, unsigned int reg)
389 +{
390 + switch (reg) {
391 + case ISABRECODEC_REG_01:
392 + case ISABRECODEC_REG_02:
393 + case ISABRECODEC_REG_10:
394 + case ISABRECODEC_REG_20:
395 + case ISABRECODEC_REG_21:
396 + case ISABRECODEC_REG_22:
397 + case ISABRECODEC_REG_24:
398 + return true;
399 +
400 + default:
401 + return false;
402 + }
403 +}
404 +
405 +static bool i_sabre_codec_volatile(struct device *dev, unsigned int reg)
406 +{
407 + switch (reg) {
408 + case ISABRECODEC_REG_01:
409 + case ISABRECODEC_REG_02:
410 + return true;
411 +
412 + default:
413 + return false;
414 + }
415 +}
416 +
417 +
418 +/* Volume Scale */
419 +static const DECLARE_TLV_DB_SCALE(volume_tlv, -10000, 100, 0);
420 +
421 +
422 +/* Filter Type */
423 +static const char * const fir_filter_type_texts[] = {
424 + "brick wall",
425 + "corrected minimum phase fast",
426 + "minimum phase slow",
427 + "minimum phase fast",
428 + "linear phase slow",
429 + "linear phase fast",
430 + "apodizing fast",
431 +};
432 +
433 +static SOC_ENUM_SINGLE_DECL(i_sabre_fir_filter_type_enum,
434 + ISABRECODEC_REG_22, 0, fir_filter_type_texts);
435 +
436 +
437 +/* I2S / SPDIF Select */
438 +static const char * const iis_spdif_sel_texts[] = {
439 + "I2S",
440 + "SPDIF",
441 +};
442 +
443 +static SOC_ENUM_SINGLE_DECL(i_sabre_iis_spdif_sel_enum,
444 + ISABRECODEC_REG_24, 0, iis_spdif_sel_texts);
445 +
446 +
447 +/* Control */
448 +static const struct snd_kcontrol_new i_sabre_codec_controls[] = {
449 +SOC_SINGLE_RANGE_TLV("Digital Playback Volume", ISABRECODEC_REG_20, 0, 0, 100, 1, volume_tlv),
450 +SOC_SINGLE("Digital Playback Switch", ISABRECODEC_REG_21, 0, 1, 1),
451 +SOC_ENUM("FIR Filter Type", i_sabre_fir_filter_type_enum),
452 +SOC_ENUM("I2S/SPDIF Select", i_sabre_iis_spdif_sel_enum),
453 +};
454 +
455 +
456 +static const u32 i_sabre_codec_dai_rates_slave[] = {
457 + 8000, 11025, 16000, 22050, 32000,
458 + 44100, 48000, 64000, 88200, 96000,
459 + 176400, 192000, 352800, 384000,
460 + 705600, 768000, 1411200, 1536000
461 +};
462 +
463 +static const struct snd_pcm_hw_constraint_list constraints_slave = {
464 + .list = i_sabre_codec_dai_rates_slave,
465 + .count = ARRAY_SIZE(i_sabre_codec_dai_rates_slave),
466 +};
467 +
468 +static int i_sabre_codec_dai_startup_slave(
469 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
470 +{
471 + struct snd_soc_component *component = dai->component;
472 + int ret;
473 +
474 + ret = snd_pcm_hw_constraint_list(substream->runtime,
475 + 0, SNDRV_PCM_HW_PARAM_RATE, &constraints_slave);
476 + if (ret != 0) {
477 + dev_err(component->card->dev, "Failed to setup rates constraints: %d\n", ret);
478 + }
479 +
480 + return ret;
481 +}
482 +
483 +static int i_sabre_codec_dai_startup(
484 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
485 +{
486 + struct snd_soc_component *component = dai->component;
487 + struct i_sabre_codec_priv *i_sabre_codec
488 + = snd_soc_component_get_drvdata(component);
489 +
490 + switch (i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
491 + case SND_SOC_DAIFMT_CBS_CFS:
492 + return i_sabre_codec_dai_startup_slave(substream, dai);
493 +
494 + default:
495 + return (-EINVAL);
496 + }
497 +}
498 +
499 +static int i_sabre_codec_hw_params(
500 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params,
501 + struct snd_soc_dai *dai)
502 +{
503 + struct snd_soc_component *component = dai->component;
504 + struct i_sabre_codec_priv *i_sabre_codec
505 + = snd_soc_component_get_drvdata(component);
506 + unsigned int daifmt;
507 + int format_width;
508 +
509 + dev_dbg(component->card->dev, "hw_params %u Hz, %u channels\n",
510 + params_rate(params), params_channels(params));
511 +
512 + /* Check I2S Format (Bit Size) */
513 + format_width = snd_pcm_format_width(params_format(params));
514 + if ((format_width != 32) && (format_width != 16)) {
515 + dev_err(component->card->dev, "Bad frame size: %d\n",
516 + snd_pcm_format_width(params_format(params)));
517 + return (-EINVAL);
518 + }
519 +
520 + /* Check Slave Mode */
521 + daifmt = i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK;
522 + if (daifmt != SND_SOC_DAIFMT_CBS_CFS) {
523 + return (-EINVAL);
524 + }
525 +
526 + /* Notify Sampling Frequency */
527 + switch (params_rate(params))
528 + {
529 + case 44100:
530 + case 48000:
531 + case 88200:
532 + case 96000:
533 + case 176400:
534 + case 192000:
535 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x00);
536 + break;
537 +
538 + case 352800:
539 + case 384000:
540 + case 705600:
541 + case 768000:
542 + case 1411200:
543 + case 1536000:
544 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x01);
545 + break;
546 + }
547 +
548 + return 0;
549 +}
550 +
551 +static int i_sabre_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
552 +{
553 + struct snd_soc_component *component = dai->component;
554 + struct i_sabre_codec_priv *i_sabre_codec
555 + = snd_soc_component_get_drvdata(component);
556 +
557 + /* interface format */
558 + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
559 + case SND_SOC_DAIFMT_I2S:
560 + break;
561 +
562 + case SND_SOC_DAIFMT_RIGHT_J:
563 + case SND_SOC_DAIFMT_LEFT_J:
564 + default:
565 + return (-EINVAL);
566 + }
567 +
568 + /* clock inversion */
569 + if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF) {
570 + return (-EINVAL);
571 + }
572 +
573 + /* Set Audio Data Format */
574 + i_sabre_codec->fmt = fmt;
575 +
576 + return 0;
577 +}
578 +
579 +static int i_sabre_codec_dac_mute(struct snd_soc_dai *dai, int mute)
580 +{
581 + struct snd_soc_component *component = dai->component;
582 +
583 + if (mute) {
584 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x01);
585 + } else {
586 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x00);
587 + }
588 +
589 + return 0;
590 +}
591 +
592 +
593 +static const struct snd_soc_dai_ops i_sabre_codec_dai_ops = {
594 + .startup = i_sabre_codec_dai_startup,
595 + .hw_params = i_sabre_codec_hw_params,
596 + .set_fmt = i_sabre_codec_set_fmt,
597 + .digital_mute = i_sabre_codec_dac_mute,
598 +};
599 +
600 +static struct snd_soc_dai_driver i_sabre_codec_dai = {
601 + .name = "i-sabre-codec-dai",
602 + .playback = {
603 + .stream_name = "Playback",
604 + .channels_min = 2,
605 + .channels_max = 2,
606 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
607 + .rate_min = 8000,
608 + .rate_max = 1536000,
609 + .formats = SNDRV_PCM_FMTBIT_S16_LE
610 + | SNDRV_PCM_FMTBIT_S32_LE,
611 + },
612 + .ops = &i_sabre_codec_dai_ops,
613 +};
614 +
615 +static struct snd_soc_component_driver i_sabre_codec_codec_driver = {
616 + .controls = i_sabre_codec_controls,
617 + .num_controls = ARRAY_SIZE(i_sabre_codec_controls),
618 +};
619 +
620 +
621 +static const struct regmap_config i_sabre_codec_regmap = {
622 + .reg_bits = 8,
623 + .val_bits = 8,
624 + .max_register = ISABRECODEC_MAX_REG,
625 +
626 + .reg_defaults = i_sabre_codec_reg_defaults,
627 + .num_reg_defaults = ARRAY_SIZE(i_sabre_codec_reg_defaults),
628 +
629 + .writeable_reg = i_sabre_codec_writeable,
630 + .readable_reg = i_sabre_codec_readable,
631 + .volatile_reg = i_sabre_codec_volatile,
632 +
633 + .cache_type = REGCACHE_RBTREE,
634 +};
635 +
636 +
637 +static int i_sabre_codec_probe(struct device *dev, struct regmap *regmap)
638 +{
639 + struct i_sabre_codec_priv *i_sabre_codec;
640 + int ret;
641 +
642 + i_sabre_codec = devm_kzalloc(dev, sizeof(*i_sabre_codec), GFP_KERNEL);
643 + if (!i_sabre_codec) {
644 + dev_err(dev, "devm_kzalloc");
645 + return (-ENOMEM);
646 + }
647 +
648 + i_sabre_codec->regmap = regmap;
649 +
650 + dev_set_drvdata(dev, i_sabre_codec);
651 +
652 + ret = snd_soc_register_component(dev,
653 + &i_sabre_codec_codec_driver, &i_sabre_codec_dai, 1);
654 + if (ret != 0) {
655 + dev_err(dev, "Failed to register CODEC: %d\n", ret);
656 + return ret;
657 + }
658 +
659 + return 0;
660 +}
661 +
662 +static void i_sabre_codec_remove(struct device *dev)
663 +{
664 + snd_soc_unregister_component(dev);
665 +}
666 +
667 +
668 +static int i_sabre_codec_i2c_probe(
669 + struct i2c_client *i2c, const struct i2c_device_id *id)
670 +{
671 + struct regmap *regmap;
672 +
673 + regmap = devm_regmap_init_i2c(i2c, &i_sabre_codec_regmap);
674 + if (IS_ERR(regmap)) {
675 + return PTR_ERR(regmap);
676 + }
677 +
678 + return i_sabre_codec_probe(&i2c->dev, regmap);
679 +}
680 +
681 +static int i_sabre_codec_i2c_remove(struct i2c_client *i2c)
682 +{
683 + i_sabre_codec_remove(&i2c->dev);
684 +
685 + return 0;
686 +}
687 +
688 +
689 +static const struct i2c_device_id i_sabre_codec_i2c_id[] = {
690 + { "i-sabre-codec", },
691 + { }
692 +};
693 +MODULE_DEVICE_TABLE(i2c, i_sabre_codec_i2c_id);
694 +
695 +static const struct of_device_id i_sabre_codec_of_match[] = {
696 + { .compatible = "audiophonics,i-sabre-codec", },
697 + { }
698 +};
699 +MODULE_DEVICE_TABLE(of, i_sabre_codec_of_match);
700 +
701 +static struct i2c_driver i_sabre_codec_i2c_driver = {
702 + .driver = {
703 + .name = "i-sabre-codec-i2c",
704 + .owner = THIS_MODULE,
705 + .of_match_table = of_match_ptr(i_sabre_codec_of_match),
706 + },
707 + .probe = i_sabre_codec_i2c_probe,
708 + .remove = i_sabre_codec_i2c_remove,
709 + .id_table = i_sabre_codec_i2c_id,
710 +};
711 +module_i2c_driver(i_sabre_codec_i2c_driver);
712 +
713 +
714 +MODULE_DESCRIPTION("ASoC I-Sabre Q2M codec driver");
715 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
716 +MODULE_LICENSE("GPL");
717 --- /dev/null
718 +++ b/sound/soc/codecs/i-sabre-codec.h
719 @@ -0,0 +1,42 @@
720 +/*
721 + * Driver for I-Sabre Q2M
722 + *
723 + * Author: Satoru Kawase
724 + * Modified by: Xiao Qingyong
725 + * Copyright 2018 Audiophonics
726 + *
727 + * This program is free software; you can redistribute it and/or
728 + * modify it under the terms of the GNU General Public License
729 + * version 2 as published by the Free Software Foundation.
730 + *
731 + * This program is distributed in the hope that it will be useful, but
732 + * WITHOUT ANY WARRANTY; without even the implied warranty of
733 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
734 + * General Public License for more details.
735 + */
736 +
737 +#ifndef _SND_SOC_ISABRECODEC
738 +#define _SND_SOC_ISABRECODEC
739 +
740 +
741 +/* ISABRECODEC Register Address */
742 +#define ISABRECODEC_REG_01 0x01 /* Virtual Device ID : 0x01 = es9038q2m */
743 +#define ISABRECODEC_REG_02 0x02 /* API revision : 0x01 = Revision 01 */
744 +#define ISABRECODEC_REG_10 0x10 /* 0x01 = above 192kHz, 0x00 = otherwise */
745 +#define ISABRECODEC_REG_20 0x20 /* 0 - 100 (decimal value, 0 = min., 100 = max.) */
746 +#define ISABRECODEC_REG_21 0x21 /* 0x00 = Mute OFF, 0x01 = Mute ON */
747 +#define ISABRECODEC_REG_22 0x22
748 +/*
749 + 0x00 = brick wall,
750 + 0x01 = corrected minimum phase fast,
751 + 0x02 = minimum phase slow,
752 + 0x03 = minimum phase fast,
753 + 0x04 = linear phase slow,
754 + 0x05 = linear phase fast,
755 + 0x06 = apodizing fast,
756 +*/
757 +//#define ISABRECODEC_REG_23 0x23 /* reserved */
758 +#define ISABRECODEC_REG_24 0x24 /* 0x00 = I2S, 0x01 = SPDIF */
759 +#define ISABRECODEC_MAX_REG 0x24 /* Maximum Register Number */
760 +
761 +#endif /* _SND_SOC_ISABRECODEC */