1 From 0cf49c5a3e560901a98562abb00f8402f1ac3a14 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 411/773] Audiophonics I-Sabre 9038Q2M DAC driver
6 Signed-off-by: Audiophonics <contact@audiophonics.fr>
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 arch/arm/configs/bcm2709_defconfig | 1 +
12 arch/arm/configs/bcmrpi_defconfig | 1 +
13 arch/arm64/configs/bcmrpi3_defconfig | 1 +
14 sound/soc/bcm/Kconfig | 7 +
15 sound/soc/bcm/Makefile | 2 +
16 sound/soc/bcm/i-sabre-q2m.c | 157 +++++++
17 sound/soc/codecs/Kconfig | 5 +
18 sound/soc/codecs/Makefile | 2 +
19 sound/soc/codecs/i-sabre-codec.c | 392 ++++++++++++++++++
20 sound/soc/codecs/i-sabre-codec.h | 42 ++
21 13 files changed, 656 insertions(+)
22 create mode 100644 arch/arm/boot/dts/overlays/i-sabre-q2m-overlay.dts
23 create mode 100644 sound/soc/bcm/i-sabre-q2m.c
24 create mode 100644 sound/soc/codecs/i-sabre-codec.c
25 create mode 100644 sound/soc/codecs/i-sabre-codec.h
27 --- a/arch/arm/boot/dts/overlays/Makefile
28 +++ b/arch/arm/boot/dts/overlays/Makefile
29 @@ -55,6 +55,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
37 --- a/arch/arm/boot/dts/overlays/README
38 +++ b/arch/arm/boot/dts/overlays/README
39 @@ -869,6 +869,12 @@ Params: speed Display
40 ledgpio GPIO used to control backlight
44 +Info: Configures the Audiophonics I-SABRE Q2M DAC
45 +Load: dtoverlay=i-sabre-q2m
50 Info: Fall back to the i2c_bcm2708 driver for the i2c_arm bus.
51 Load: dtoverlay=i2c-bcm2708
53 +++ b/arch/arm/boot/dts/overlays/i-sabre-q2m-overlay.dts
55 +// Definitions for I-Sabre Q2M
60 + compatible = "brcm,bcm2708";
64 + frag0: __overlay__ {
65 + compatible = "audiophonics,i-sabre-q2m";
66 + i2s-controller = <&i2s>;
81 + #address-cells = <1>;
86 + #sound-dai-cells = <0>;
87 + compatible = "audiophonics,i-sabre-codec";
94 --- a/arch/arm/configs/bcm2709_defconfig
95 +++ b/arch/arm/configs/bcm2709_defconfig
96 @@ -916,6 +916,7 @@ CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC=m
97 CONFIG_SND_BCM2708_SOC_JUSTBOOM_DIGI=m
98 CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
99 CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI=m
100 +CONFIG_SND_BCM2708_SOC_I_SABRE_Q2M=m
101 CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
102 CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
103 CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD=m
104 --- a/arch/arm/configs/bcmrpi_defconfig
105 +++ b/arch/arm/configs/bcmrpi_defconfig
106 @@ -909,6 +909,7 @@ CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC=m
107 CONFIG_SND_BCM2708_SOC_JUSTBOOM_DIGI=m
108 CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
109 CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI=m
110 +CONFIG_SND_BCM2708_SOC_I_SABRE_Q2M=m
111 CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
112 CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
113 CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD=m
114 --- a/arch/arm64/configs/bcmrpi3_defconfig
115 +++ b/arch/arm64/configs/bcmrpi3_defconfig
116 @@ -804,6 +804,7 @@ CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC=m
117 CONFIG_SND_BCM2708_SOC_JUSTBOOM_DIGI=m
118 CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
119 CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI=m
120 +CONFIG_SND_BCM2708_SOC_I_SABRE_Q2M=m
121 CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
122 CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
123 CONFIG_SND_AUDIOSENSE_PI=m
124 --- a/sound/soc/bcm/Kconfig
125 +++ b/sound/soc/bcm/Kconfig
126 @@ -123,6 +123,13 @@ config SND_BCM2708_SOC_IQAUDIO_DIGI
128 Say Y or M if you want to add support for IQAudIO Digital IO board.
130 +config SND_BCM2708_SOC_I_SABRE_Q2M
131 + tristate "Support for Audiophonics I-Sabre Q2M DAC"
132 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
133 + select SND_SOC_I_SABRE_CODEC
135 + Say Y or M if you want to add support for Audiophonics I-SABRE Q2M DAC
137 config SND_BCM2708_SOC_ADAU1977_ADC
138 tristate "Support for ADAU1977 ADC"
139 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
140 --- a/sound/soc/bcm/Makefile
141 +++ b/sound/soc/bcm/Makefile
142 @@ -19,6 +19,7 @@ snd-soc-justboom-dac-objs := justboom-da
143 snd-soc-rpi-cirrus-objs := rpi-cirrus.o
144 snd-soc-rpi-proto-objs := rpi-proto.o
145 snd-soc-iqaudio-dac-objs := iqaudio-dac.o
146 + snd-soc-i-sabre-q2m-objs := i-sabre-q2m.o
147 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
148 snd-soc-audioinjector-octo-soundcard-objs := audioinjector-octo-soundcard.o
149 snd-soc-audiosense-pi-objs := audiosense-pi.o
150 @@ -42,6 +43,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DA
151 obj-$(CONFIG_SND_BCM2708_SOC_RPI_CIRRUS) += snd-soc-rpi-cirrus.o
152 obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
153 obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
154 + obj-$(CONFIG_SND_BCM2708_SOC_I_SABRE_Q2M) += snd-soc-i-sabre-q2m.o
155 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
156 obj-$(CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD) += snd-soc-audioinjector-octo-soundcard.o
157 obj-$(CONFIG_SND_AUDIOSENSE_PI) += snd-soc-audiosense-pi.o
159 +++ b/sound/soc/bcm/i-sabre-q2m.c
162 + * ASoC Driver for I-Sabre Q2M
164 + * Author: Satoru Kawase
165 + * Modified by: Xiao Qingyong
166 + * Update kernel v4.18+ by : Audiophonics
167 + * Copyright 2018 Audiophonics
169 + * This program is free software; you can redistribute it and/or
170 + * modify it under the terms of the GNU General Public License
171 + * version 2 as published by the Free Software Foundation.
173 + * This program is distributed in the hope that it will be useful, but
174 + * WITHOUT ANY WARRANTY; without even the implied warranty of
175 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
176 + * General Public License for more details.
179 +#include <linux/kernel.h>
180 +#include <linux/init.h>
181 +#include <linux/module.h>
182 +#include <linux/delay.h>
183 +#include <linux/fs.h>
184 +#include <asm/uaccess.h>
185 +#include <sound/core.h>
186 +#include <sound/soc.h>
187 +#include <sound/pcm.h>
188 +#include <sound/pcm_params.h>
190 +#include "../codecs/i-sabre-codec.h"
193 +static int snd_rpi_i_sabre_q2m_init(struct snd_soc_pcm_runtime *rtd)
195 + struct snd_soc_component *component = rtd->codec_dai->component;
196 + unsigned int value;
199 + value = snd_soc_component_read32(component, ISABRECODEC_REG_01);
200 + dev_info(component->card->dev, "Audiophonics Device ID : %02X\n", value);
203 + value = snd_soc_component_read32(component, ISABRECODEC_REG_02);
204 + dev_info(component->card->dev, "Audiophonics API revision : %02X\n", value);
209 +static int snd_rpi_i_sabre_q2m_hw_params(
210 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
212 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
213 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
216 + bclk_ratio = snd_pcm_format_physical_width(
217 + params_format(params)) * params_channels(params);
218 + return snd_soc_dai_set_bclk_ratio(cpu_dai, bclk_ratio);
221 +/* machine stream operations */
222 +static struct snd_soc_ops snd_rpi_i_sabre_q2m_ops = {
223 + .hw_params = snd_rpi_i_sabre_q2m_hw_params,
227 +static struct snd_soc_dai_link snd_rpi_i_sabre_q2m_dai[] = {
229 + .name = "I-Sabre Q2M",
230 + .stream_name = "I-Sabre Q2M DAC",
231 + .cpu_dai_name = "bcm2708-i2s.0",
232 + .codec_dai_name = "i-sabre-codec-dai",
233 + .platform_name = "bcm2708-i2s.0",
234 + .codec_name = "i-sabre-codec-i2c.1-0048",
235 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
236 + | SND_SOC_DAIFMT_CBS_CFS,
237 + .init = snd_rpi_i_sabre_q2m_init,
238 + .ops = &snd_rpi_i_sabre_q2m_ops,
242 +/* audio machine driver */
243 +static struct snd_soc_card snd_rpi_i_sabre_q2m = {
244 + .name = "I-Sabre Q2M DAC",
245 + .owner = THIS_MODULE,
246 + .dai_link = snd_rpi_i_sabre_q2m_dai,
247 + .num_links = ARRAY_SIZE(snd_rpi_i_sabre_q2m_dai)
251 +static int snd_rpi_i_sabre_q2m_probe(struct platform_device *pdev)
255 + snd_rpi_i_sabre_q2m.dev = &pdev->dev;
256 + if (pdev->dev.of_node) {
257 + struct device_node *i2s_node;
258 + struct snd_soc_dai_link *dai;
260 + dai = &snd_rpi_i_sabre_q2m_dai[0];
261 + i2s_node = of_parse_phandle(pdev->dev.of_node,
262 + "i2s-controller", 0);
264 + dai->cpu_dai_name = NULL;
265 + dai->cpu_of_node = i2s_node;
266 + dai->platform_name = NULL;
267 + dai->platform_of_node = i2s_node;
269 + dev_err(&pdev->dev,
270 + "Property 'i2s-controller' missing or invalid\n");
274 + dai->name = "I-Sabre Q2M";
275 + dai->stream_name = "I-Sabre Q2M DAC";
276 + dai->dai_fmt = SND_SOC_DAIFMT_I2S
277 + | SND_SOC_DAIFMT_NB_NF
278 + | SND_SOC_DAIFMT_CBS_CFS;
281 + /* Wait for registering codec driver */
284 + ret = snd_soc_register_card(&snd_rpi_i_sabre_q2m);
286 + dev_err(&pdev->dev,
287 + "snd_soc_register_card() failed: %d\n", ret);
293 +static int snd_rpi_i_sabre_q2m_remove(struct platform_device *pdev)
295 + return snd_soc_unregister_card(&snd_rpi_i_sabre_q2m);
298 +static const struct of_device_id snd_rpi_i_sabre_q2m_of_match[] = {
299 + { .compatible = "audiophonics,i-sabre-q2m", },
302 +MODULE_DEVICE_TABLE(of, snd_rpi_i_sabre_q2m_of_match);
304 +static struct platform_driver snd_rpi_i_sabre_q2m_driver = {
306 + .name = "snd-rpi-i-sabre-q2m",
307 + .owner = THIS_MODULE,
308 + .of_match_table = snd_rpi_i_sabre_q2m_of_match,
310 + .probe = snd_rpi_i_sabre_q2m_probe,
311 + .remove = snd_rpi_i_sabre_q2m_remove,
313 +module_platform_driver(snd_rpi_i_sabre_q2m_driver);
315 +MODULE_DESCRIPTION("ASoC Driver for I-Sabre Q2M");
316 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
317 +MODULE_LICENSE("GPL");
318 --- a/sound/soc/codecs/Kconfig
319 +++ b/sound/soc/codecs/Kconfig
320 @@ -85,6 +85,7 @@ config SND_SOC_ALL_CODECS
321 select SND_SOC_ICS43432
322 select SND_SOC_INNO_RK3036
323 select SND_SOC_ISABELLE if I2C
324 + select SND_SOC_I_SABRE_CODEC if I2C
325 select SND_SOC_JZ4740_CODEC
326 select SND_SOC_LM4857 if I2C
327 select SND_SOC_LM49453 if I2C
328 @@ -1322,4 +1323,8 @@ config SND_SOC_TPA6130A2
329 tristate "Texas Instruments TPA6130A2 headphone amplifier"
332 +config SND_SOC_I_SABRE_CODEC
333 + tristate "Audiophonics I-SABRE Codec"
337 --- a/sound/soc/codecs/Makefile
338 +++ b/sound/soc/codecs/Makefile
339 @@ -81,6 +81,7 @@ snd-soc-hdac-hdmi-objs := hdac_hdmi.o
340 snd-soc-ics43432-objs := ics43432.o
341 snd-soc-inno-rk3036-objs := inno_rk3036.o
342 snd-soc-isabelle-objs := isabelle.o
343 +snd-soc-i-sabre-codec-objs := i-sabre-codec.o
344 snd-soc-jz4740-codec-objs := jz4740.o
345 snd-soc-l3-objs := l3.o
346 snd-soc-lm4857-objs := lm4857.o
347 @@ -343,6 +344,7 @@ obj-$(CONFIG_SND_SOC_HDAC_HDMI) += snd-s
348 obj-$(CONFIG_SND_SOC_ICS43432) += snd-soc-ics43432.o
349 obj-$(CONFIG_SND_SOC_INNO_RK3036) += snd-soc-inno-rk3036.o
350 obj-$(CONFIG_SND_SOC_ISABELLE) += snd-soc-isabelle.o
351 +obj-$(CONFIG_SND_SOC_I_SABRE_CODEC) += snd-soc-i-sabre-codec.o
352 obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o
353 obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
354 obj-$(CONFIG_SND_SOC_LM4857) += snd-soc-lm4857.o
356 +++ b/sound/soc/codecs/i-sabre-codec.c
359 + * Driver for I-Sabre Q2M
361 + * Author: Satoru Kawase
362 + * Modified by: Xiao Qingyong
363 + * Modified by: JC BARBAUD (Mute)
364 + * Update kernel v4.18+ by : Audiophonics
365 + * Copyright 2018 Audiophonics
367 + * This program is free software; you can redistribute it and/or
368 + * modify it under the terms of the GNU General Public License
369 + * version 2 as published by the Free Software Foundation.
371 + * This program is distributed in the hope that it will be useful, but
372 + * WITHOUT ANY WARRANTY; without even the implied warranty of
373 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
374 + * General Public License for more details.
378 +#include <linux/init.h>
379 +#include <linux/module.h>
380 +#include <linux/regmap.h>
381 +#include <linux/i2c.h>
382 +#include <sound/soc.h>
383 +#include <sound/pcm_params.h>
384 +#include <sound/tlv.h>
386 +#include "i-sabre-codec.h"
389 +/* I-Sabre Q2M Codec Private Data */
390 +struct i_sabre_codec_priv {
391 + struct regmap *regmap;
396 +/* I-Sabre Q2M Codec Default Register Value */
397 +static const struct reg_default i_sabre_codec_reg_defaults[] = {
398 + { ISABRECODEC_REG_10, 0x00 },
399 + { ISABRECODEC_REG_20, 0x00 },
400 + { ISABRECODEC_REG_21, 0x00 },
401 + { ISABRECODEC_REG_22, 0x00 },
402 + { ISABRECODEC_REG_24, 0x00 },
406 +static bool i_sabre_codec_writeable(struct device *dev, unsigned int reg)
409 + case ISABRECODEC_REG_10:
410 + case ISABRECODEC_REG_20:
411 + case ISABRECODEC_REG_21:
412 + case ISABRECODEC_REG_22:
413 + case ISABRECODEC_REG_24:
421 +static bool i_sabre_codec_readable(struct device *dev, unsigned int reg)
424 + case ISABRECODEC_REG_01:
425 + case ISABRECODEC_REG_02:
426 + case ISABRECODEC_REG_10:
427 + case ISABRECODEC_REG_20:
428 + case ISABRECODEC_REG_21:
429 + case ISABRECODEC_REG_22:
430 + case ISABRECODEC_REG_24:
438 +static bool i_sabre_codec_volatile(struct device *dev, unsigned int reg)
441 + case ISABRECODEC_REG_01:
442 + case ISABRECODEC_REG_02:
452 +static const DECLARE_TLV_DB_SCALE(volume_tlv, -10000, 100, 0);
456 +static const char * const fir_filter_type_texts[] = {
458 + "corrected minimum phase fast",
459 + "minimum phase slow",
460 + "minimum phase fast",
461 + "linear phase slow",
462 + "linear phase fast",
466 +static SOC_ENUM_SINGLE_DECL(i_sabre_fir_filter_type_enum,
467 + ISABRECODEC_REG_22, 0, fir_filter_type_texts);
470 +/* I2S / SPDIF Select */
471 +static const char * const iis_spdif_sel_texts[] = {
476 +static SOC_ENUM_SINGLE_DECL(i_sabre_iis_spdif_sel_enum,
477 + ISABRECODEC_REG_24, 0, iis_spdif_sel_texts);
481 +static const struct snd_kcontrol_new i_sabre_codec_controls[] = {
482 +SOC_SINGLE_RANGE_TLV("Digital Playback Volume", ISABRECODEC_REG_20, 0, 0, 100, 1, volume_tlv),
483 +SOC_SINGLE("Digital Playback Switch", ISABRECODEC_REG_21, 0, 1, 1),
484 +SOC_ENUM("FIR Filter Type", i_sabre_fir_filter_type_enum),
485 +SOC_ENUM("I2S/SPDIF Select", i_sabre_iis_spdif_sel_enum),
489 +static const u32 i_sabre_codec_dai_rates_slave[] = {
490 + 8000, 11025, 16000, 22050, 32000,
491 + 44100, 48000, 64000, 88200, 96000,
492 + 176400, 192000, 352800, 384000,
493 + 705600, 768000, 1411200, 1536000
496 +static const struct snd_pcm_hw_constraint_list constraints_slave = {
497 + .list = i_sabre_codec_dai_rates_slave,
498 + .count = ARRAY_SIZE(i_sabre_codec_dai_rates_slave),
501 +static int i_sabre_codec_dai_startup_slave(
502 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
504 + struct snd_soc_component *component = dai->component;
507 + ret = snd_pcm_hw_constraint_list(substream->runtime,
508 + 0, SNDRV_PCM_HW_PARAM_RATE, &constraints_slave);
510 + dev_err(component->card->dev, "Failed to setup rates constraints: %d\n", ret);
516 +static int i_sabre_codec_dai_startup(
517 + struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
519 + struct snd_soc_component *component = dai->component;
520 + struct i_sabre_codec_priv *i_sabre_codec
521 + = snd_soc_component_get_drvdata(component);
523 + switch (i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
524 + case SND_SOC_DAIFMT_CBS_CFS:
525 + return i_sabre_codec_dai_startup_slave(substream, dai);
532 +static int i_sabre_codec_hw_params(
533 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params,
534 + struct snd_soc_dai *dai)
536 + struct snd_soc_component *component = dai->component;
537 + struct i_sabre_codec_priv *i_sabre_codec
538 + = snd_soc_component_get_drvdata(component);
539 + unsigned int daifmt;
542 + dev_dbg(component->card->dev, "hw_params %u Hz, %u channels\n",
543 + params_rate(params), params_channels(params));
545 + /* Check I2S Format (Bit Size) */
546 + format_width = snd_pcm_format_width(params_format(params));
547 + if ((format_width != 32) && (format_width != 16)) {
548 + dev_err(component->card->dev, "Bad frame size: %d\n",
549 + snd_pcm_format_width(params_format(params)));
553 + /* Check Slave Mode */
554 + daifmt = i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK;
555 + if (daifmt != SND_SOC_DAIFMT_CBS_CFS) {
559 + /* Notify Sampling Frequency */
560 + switch (params_rate(params))
568 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x00);
577 + snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x01);
584 +static int i_sabre_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
586 + struct snd_soc_component *component = dai->component;
587 + struct i_sabre_codec_priv *i_sabre_codec
588 + = snd_soc_component_get_drvdata(component);
590 + /* interface format */
591 + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
592 + case SND_SOC_DAIFMT_I2S:
595 + case SND_SOC_DAIFMT_RIGHT_J:
596 + case SND_SOC_DAIFMT_LEFT_J:
601 + /* clock inversion */
602 + if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF) {
606 + /* Set Audio Data Format */
607 + i_sabre_codec->fmt = fmt;
612 +static int i_sabre_codec_dac_mute(struct snd_soc_dai *dai, int mute)
614 + struct snd_soc_component *component = dai->component;
617 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x01);
619 + snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x00);
626 +static const struct snd_soc_dai_ops i_sabre_codec_dai_ops = {
627 + .startup = i_sabre_codec_dai_startup,
628 + .hw_params = i_sabre_codec_hw_params,
629 + .set_fmt = i_sabre_codec_set_fmt,
630 + .digital_mute = i_sabre_codec_dac_mute,
633 +static struct snd_soc_dai_driver i_sabre_codec_dai = {
634 + .name = "i-sabre-codec-dai",
636 + .stream_name = "Playback",
639 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
641 + .rate_max = 1536000,
642 + .formats = SNDRV_PCM_FMTBIT_S16_LE
643 + | SNDRV_PCM_FMTBIT_S32_LE,
645 + .ops = &i_sabre_codec_dai_ops,
648 +static struct snd_soc_component_driver i_sabre_codec_codec_driver = {
649 + .controls = i_sabre_codec_controls,
650 + .num_controls = ARRAY_SIZE(i_sabre_codec_controls),
654 +static const struct regmap_config i_sabre_codec_regmap = {
657 + .max_register = ISABRECODEC_MAX_REG,
659 + .reg_defaults = i_sabre_codec_reg_defaults,
660 + .num_reg_defaults = ARRAY_SIZE(i_sabre_codec_reg_defaults),
662 + .writeable_reg = i_sabre_codec_writeable,
663 + .readable_reg = i_sabre_codec_readable,
664 + .volatile_reg = i_sabre_codec_volatile,
666 + .cache_type = REGCACHE_RBTREE,
670 +static int i_sabre_codec_probe(struct device *dev, struct regmap *regmap)
672 + struct i_sabre_codec_priv *i_sabre_codec;
675 + i_sabre_codec = devm_kzalloc(dev, sizeof(*i_sabre_codec), GFP_KERNEL);
676 + if (!i_sabre_codec) {
677 + dev_err(dev, "devm_kzalloc");
681 + i_sabre_codec->regmap = regmap;
683 + dev_set_drvdata(dev, i_sabre_codec);
685 + ret = snd_soc_register_component(dev,
686 + &i_sabre_codec_codec_driver, &i_sabre_codec_dai, 1);
688 + dev_err(dev, "Failed to register CODEC: %d\n", ret);
695 +static void i_sabre_codec_remove(struct device *dev)
697 + snd_soc_unregister_component(dev);
701 +static int i_sabre_codec_i2c_probe(
702 + struct i2c_client *i2c, const struct i2c_device_id *id)
704 + struct regmap *regmap;
706 + regmap = devm_regmap_init_i2c(i2c, &i_sabre_codec_regmap);
707 + if (IS_ERR(regmap)) {
708 + return PTR_ERR(regmap);
711 + return i_sabre_codec_probe(&i2c->dev, regmap);
714 +static int i_sabre_codec_i2c_remove(struct i2c_client *i2c)
716 + i_sabre_codec_remove(&i2c->dev);
722 +static const struct i2c_device_id i_sabre_codec_i2c_id[] = {
723 + { "i-sabre-codec", },
726 +MODULE_DEVICE_TABLE(i2c, i_sabre_codec_i2c_id);
728 +static const struct of_device_id i_sabre_codec_of_match[] = {
729 + { .compatible = "audiophonics,i-sabre-codec", },
732 +MODULE_DEVICE_TABLE(of, i_sabre_codec_of_match);
734 +static struct i2c_driver i_sabre_codec_i2c_driver = {
736 + .name = "i-sabre-codec-i2c",
737 + .owner = THIS_MODULE,
738 + .of_match_table = of_match_ptr(i_sabre_codec_of_match),
740 + .probe = i_sabre_codec_i2c_probe,
741 + .remove = i_sabre_codec_i2c_remove,
742 + .id_table = i_sabre_codec_i2c_id,
744 +module_i2c_driver(i_sabre_codec_i2c_driver);
747 +MODULE_DESCRIPTION("ASoC I-Sabre Q2M codec driver");
748 +MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
749 +MODULE_LICENSE("GPL");
751 +++ b/sound/soc/codecs/i-sabre-codec.h
754 + * Driver for I-Sabre Q2M
756 + * Author: Satoru Kawase
757 + * Modified by: Xiao Qingyong
758 + * Copyright 2018 Audiophonics
760 + * This program is free software; you can redistribute it and/or
761 + * modify it under the terms of the GNU General Public License
762 + * version 2 as published by the Free Software Foundation.
764 + * This program is distributed in the hope that it will be useful, but
765 + * WITHOUT ANY WARRANTY; without even the implied warranty of
766 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
767 + * General Public License for more details.
770 +#ifndef _SND_SOC_ISABRECODEC
771 +#define _SND_SOC_ISABRECODEC
774 +/* ISABRECODEC Register Address */
775 +#define ISABRECODEC_REG_01 0x01 /* Virtual Device ID : 0x01 = es9038q2m */
776 +#define ISABRECODEC_REG_02 0x02 /* API revision : 0x01 = Revision 01 */
777 +#define ISABRECODEC_REG_10 0x10 /* 0x01 = above 192kHz, 0x00 = otherwise */
778 +#define ISABRECODEC_REG_20 0x20 /* 0 - 100 (decimal value, 0 = min., 100 = max.) */
779 +#define ISABRECODEC_REG_21 0x21 /* 0x00 = Mute OFF, 0x01 = Mute ON */
780 +#define ISABRECODEC_REG_22 0x22
783 + 0x01 = corrected minimum phase fast,
784 + 0x02 = minimum phase slow,
785 + 0x03 = minimum phase fast,
786 + 0x04 = linear phase slow,
787 + 0x05 = linear phase fast,
788 + 0x06 = apodizing fast,
790 +//#define ISABRECODEC_REG_23 0x23 /* reserved */
791 +#define ISABRECODEC_REG_24 0x24 /* 0x00 = I2S, 0x01 = SPDIF */
792 +#define ISABRECODEC_MAX_REG 0x24 /* Maximum Register Number */
794 +#endif /* _SND_SOC_ISABRECODEC */