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