brcm2708: update to latest patches from the RPi foundation
[openwrt/staging/lynxis.git] / target / linux / brcm2708 / patches-4.14 / 950-0283-Driver-for-Allo-Katana-DAC.patch
1 From 1db90ec599e116593cc1844ccac021707b45c5cb Mon Sep 17 00:00:00 2001
2 From: allocom <sparky-dev@allo.com>
3 Date: Tue, 24 Apr 2018 11:19:03 +0530
4 Subject: [PATCH 283/454] Driver for Allo Katana DAC
5
6 ---
7 .../allo-katana-dac-audio-overlay.dts | 27 +-
8 sound/soc/bcm/Kconfig | 4 +-
9 sound/soc/bcm/Makefile | 4 +-
10 sound/soc/bcm/allo-katana-codec.c | 363 ++++++++++++++++++
11 sound/soc/bcm/allo-katana-dac.c | 102 -----
12 sound/soc/codecs/Kconfig | 10 -
13 sound/soc/codecs/Makefile | 4 -
14 sound/soc/codecs/sabre-ess-i2c.c | 69 ----
15 sound/soc/codecs/sabre-ess.c | 300 ---------------
16 sound/soc/codecs/sabre-ess.h | 62 ---
17 10 files changed, 387 insertions(+), 558 deletions(-)
18 create mode 100644 sound/soc/bcm/allo-katana-codec.c
19 delete mode 100644 sound/soc/bcm/allo-katana-dac.c
20 delete mode 100644 sound/soc/codecs/sabre-ess-i2c.c
21 delete mode 100644 sound/soc/codecs/sabre-ess.c
22 delete mode 100644 sound/soc/codecs/sabre-ess.h
23
24 --- a/arch/arm/boot/dts/overlays/allo-katana-dac-audio-overlay.dts
25 +++ b/arch/arm/boot/dts/overlays/allo-katana-dac-audio-overlay.dts
26 @@ -1,7 +1,5 @@
27 /*
28 * Definitions for Allo Katana DAC boards
29 - *
30 - * NB. The Katana DAC board contains SABER DAC.
31 */
32
33 /dts-v1/;
34 @@ -13,7 +11,16 @@
35 fragment@0 {
36 target = <&i2s>;
37 __overlay__ {
38 + #sound-dai-cells = <0>;
39 status = "okay";
40 + cpu_port: port {
41 + cpu_endpoint: endpoint {
42 + remote-endpoint = <&codec_endpoint>;
43 + bitclock-master = <&codec_endpoint>;
44 + frame-master = <&codec_endpoint>;
45 + dai-format = "i2s";
46 + };
47 + };
48 };
49 };
50
51 @@ -24,11 +31,15 @@
52 #size-cells = <0>;
53 status = "okay";
54
55 - sabre-ess@30 {
56 + allo-katana-codec@30 {
57 #sound-dai-cells = <0>;
58 - compatible = "saber,sabre-ess";
59 + compatible = "allo,allo-katana-codec";
60 reg = <0x30>;
61 - status = "okay";
62 + port {
63 + codec_endpoint: endpoint {
64 + remote-endpoint = <&cpu_endpoint>;
65 + };
66 + };
67 };
68 };
69 };
70 @@ -36,11 +47,11 @@
71 fragment@2 {
72 target = <&sound>;
73 katana_dac: __overlay__ {
74 - compatible = "allo,katana-dac";
75 - i2s-controller = <&i2s>;
76 + compatible = "audio-graph-card";
77 + label = "Allo Katana";
78 + dais = <&cpu_port>;
79 status = "okay";
80 };
81 };
82 -
83 };
84
85 --- a/sound/soc/bcm/Kconfig
86 +++ b/sound/soc/bcm/Kconfig
87 @@ -178,7 +178,9 @@ config SND_BCM2708_SOC_ALLO_DIGIONE
88 config SND_BCM2708_SOC_ALLO_KATANA_DAC
89 tristate "Support for Allo Katana DAC"
90 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
91 - select SND_SOC_SABRE_ESS_I2C
92 + depends on I2C
93 + select REGMAP_I2C
94 + select SND_AUDIO_GRAPH_CARD
95 help
96 Say Y or M if you want to add support for Allo Katana DAC.
97
98 --- a/sound/soc/bcm/Makefile
99 +++ b/sound/soc/bcm/Makefile
100 @@ -34,7 +34,7 @@ snd-soc-allo-boss-dac-objs := allo-boss-
101 snd-soc-allo-piano-dac-objs := allo-piano-dac.o
102 snd-soc-allo-piano-dac-plus-objs := allo-piano-dac-plus.o
103 snd-soc-allo-digione-objs := allo-digione.o
104 -snd-soc-allo-katana-dac-objs := allo-katana-dac.o
105 +snd-soc-allo-katana-codec-objs := allo-katana-codec.o
106 snd-soc-pisound-objs := pisound.o
107 snd-soc-fe-pi-audio-objs := fe-pi-audio.o
108
109 @@ -61,6 +61,6 @@ obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_D
110 obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
111 obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS) += snd-soc-allo-piano-dac-plus.o
112 obj-$(CONFIG_SND_BCM2708_SOC_ALLO_DIGIONE) += snd-soc-allo-digione.o
113 -obj-$(CONFIG_SND_BCM2708_SOC_ALLO_KATANA_DAC) += snd-soc-allo-katana-dac.o
114 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_KATANA_DAC) += snd-soc-allo-katana-codec.o
115 obj-$(CONFIG_SND_PISOUND) += snd-soc-pisound.o
116 obj-$(CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO) += snd-soc-fe-pi-audio.o
117 --- /dev/null
118 +++ b/sound/soc/bcm/allo-katana-codec.c
119 @@ -0,0 +1,363 @@
120 +/*
121 + * Driver for the ALLO KATANA CODEC
122 + *
123 + * Author: Jaikumar <jaikumar@cem-solutions.net>
124 + * Copyright 2018
125 + *
126 + * This program is free software; you can redistribute it and/or
127 + * modify it under the terms of the GNU General Public License
128 + * version 2 as published by the Free Software Foundation.
129 + *
130 + * This program is distributed in the hope that it will be useful, but
131 + * WITHOUT ANY WARRANTY; without even the implied warranty of
132 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
133 + * General Public License for more details.
134 + */
135 +
136 +
137 +#include <linux/init.h>
138 +#include <linux/module.h>
139 +#include <linux/clk.h>
140 +#include <linux/kernel.h>
141 +#include <linux/regmap.h>
142 +#include <linux/regulator/consumer.h>
143 +#include <linux/gcd.h>
144 +#include <sound/soc.h>
145 +#include <sound/soc-dapm.h>
146 +#include <sound/pcm_params.h>
147 +#include <sound/tlv.h>
148 +#include <linux/i2c.h>
149 +
150 +
151 +#define KATANA_CODEC_CHIP_ID 0x30
152 +#define KATANA_CODEC_VIRT_BASE 0x100
153 +#define KATANA_CODEC_PAGE 0
154 +
155 +#define KATANA_CODEC_CHIP_ID_REG (KATANA_CODEC_VIRT_BASE + 0)
156 +#define KATANA_CODEC_RESET (KATANA_CODEC_VIRT_BASE + 1)
157 +#define KATANA_CODEC_VOLUME_1 (KATANA_CODEC_VIRT_BASE + 2)
158 +#define KATANA_CODEC_VOLUME_2 (KATANA_CODEC_VIRT_BASE + 3)
159 +#define KATANA_CODEC_MUTE (KATANA_CODEC_VIRT_BASE + 4)
160 +#define KATANA_CODEC_DSP_PROGRAM (KATANA_CODEC_VIRT_BASE + 5)
161 +#define KATANA_CODEC_DEEMPHASIS (KATANA_CODEC_VIRT_BASE + 6)
162 +#define KATANA_CODEC_DOP (KATANA_CODEC_VIRT_BASE + 7)
163 +#define KATANA_CODEC_FORMAT (KATANA_CODEC_VIRT_BASE + 8)
164 +#define KATANA_CODEC_COMMAND (KATANA_CODEC_VIRT_BASE + 9)
165 +#define KATANA_CODEC_MAX_REGISTER (KATANA_CODEC_VIRT_BASE + 9)
166 +
167 +#define KATANA_CODEC_FMT 0xff
168 +#define KATANA_CODEC_CHAN_MONO 0x00
169 +#define KATANA_CODEC_CHAN_STEREO 0x80
170 +#define KATANA_CODEC_ALEN_16 0x10
171 +#define KATANA_CODEC_ALEN_24 0x20
172 +#define KATANA_CODEC_ALEN_32 0x30
173 +#define KATANA_CODEC_RATE_11025 0x01
174 +#define KATANA_CODEC_RATE_22050 0x02
175 +#define KATANA_CODEC_RATE_32000 0x03
176 +#define KATANA_CODEC_RATE_44100 0x04
177 +#define KATANA_CODEC_RATE_48000 0x05
178 +#define KATANA_CODEC_RATE_88200 0x06
179 +#define KATANA_CODEC_RATE_96000 0x07
180 +#define KATANA_CODEC_RATE_176400 0x08
181 +#define KATANA_CODEC_RATE_192000 0x09
182 +#define KATANA_CODEC_RATE_352800 0x0a
183 +#define KATANA_CODEC_RATE_384000 0x0b
184 +
185 +
186 +struct katana_codec_priv {
187 + struct regmap *regmap;
188 + int fmt;
189 +};
190 +
191 +static const struct reg_default katana_codec_reg_defaults[] = {
192 + { KATANA_CODEC_RESET, 0x00 },
193 + { KATANA_CODEC_VOLUME_1, 0xF0 },
194 + { KATANA_CODEC_VOLUME_2, 0xF0 },
195 + { KATANA_CODEC_MUTE, 0x00 },
196 + { KATANA_CODEC_DSP_PROGRAM, 0x04 },
197 + { KATANA_CODEC_DEEMPHASIS, 0x00 },
198 + { KATANA_CODEC_DOP, 0x01 },
199 + { KATANA_CODEC_FORMAT, 0xb4 },
200 +};
201 +
202 +static const char * const katana_codec_dsp_program_texts[] = {
203 + "Linear Phase Fast Roll-off Filter",
204 + "Linear Phase Slow Roll-off Filter",
205 + "Minimum Phase Fast Roll-off Filter",
206 + "Minimum Phase Slow Roll-off Filter",
207 + "Apodizing Fast Roll-off Filter",
208 + "Corrected Minimum Phase Fast Roll-off Filter",
209 + "Brick Wall Filter",
210 +};
211 +
212 +static const unsigned int katana_codec_dsp_program_values[] = {
213 + 0,
214 + 1,
215 + 2,
216 + 3,
217 + 4,
218 + 6,
219 + 7,
220 +};
221 +
222 +static SOC_VALUE_ENUM_SINGLE_DECL(katana_codec_dsp_program,
223 + KATANA_CODEC_DSP_PROGRAM, 0, 0x07,
224 + katana_codec_dsp_program_texts,
225 + katana_codec_dsp_program_values);
226 +
227 +static const char * const katana_codec_deemphasis_texts[] = {
228 + "Bypass",
229 + "32kHz",
230 + "44.1kHz",
231 + "48kHz",
232 +};
233 +
234 +static const unsigned int katana_codec_deemphasis_values[] = {
235 + 0,
236 + 1,
237 + 2,
238 + 3,
239 +};
240 +
241 +static SOC_VALUE_ENUM_SINGLE_DECL(katana_codec_deemphasis,
242 + KATANA_CODEC_DEEMPHASIS, 0, 0x03,
243 + katana_codec_deemphasis_texts,
244 + katana_codec_deemphasis_values);
245 +
246 +static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12700, 0);
247 +
248 +static const struct snd_kcontrol_new katana_codec_controls[] = {
249 + SOC_DOUBLE_R_TLV("Master Playback Volume", KATANA_CODEC_VOLUME_1,
250 + KATANA_CODEC_VOLUME_2, 0, 255, 1, master_tlv),
251 + SOC_DOUBLE("Master Playback Switch", KATANA_CODEC_MUTE, 0, 0, 1, 1),
252 + SOC_ENUM("DSP Program Route", katana_codec_dsp_program),
253 + SOC_ENUM("Deemphasis Route", katana_codec_deemphasis),
254 + SOC_SINGLE("DoP Playback Switch", KATANA_CODEC_DOP, 0, 1, 1)
255 +};
256 +
257 +static bool katana_codec_readable_register(struct device *dev, unsigned int reg)
258 +{
259 + switch (reg) {
260 + case KATANA_CODEC_CHIP_ID_REG:
261 + return true;
262 + default:
263 + return reg < 0xff;
264 + }
265 +}
266 +
267 +static int katana_codec_hw_params(struct snd_pcm_substream *substream,
268 + struct snd_pcm_hw_params *params,
269 + struct snd_soc_dai *dai)
270 +{
271 + struct snd_soc_codec *codec = dai->codec;
272 + struct katana_codec_priv *katana_codec = snd_soc_codec_get_drvdata(codec);
273 + int fmt = 0;
274 + int ret;
275 +
276 + dev_dbg(codec->dev, "hw_params %u Hz, %u channels\n",
277 + params_rate(params),
278 + params_channels(params));
279 +
280 + switch (katana_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
281 + case SND_SOC_DAIFMT_CBM_CFM: // master
282 + if (params_channels(params) == 2)
283 + fmt = KATANA_CODEC_CHAN_STEREO;
284 + else
285 + fmt = KATANA_CODEC_CHAN_MONO;
286 +
287 + switch (params_width(params)) {
288 + case 16:
289 + fmt |= KATANA_CODEC_ALEN_16;
290 + break;
291 + case 24:
292 + fmt |= KATANA_CODEC_ALEN_24;
293 + break;
294 + case 32:
295 + fmt |= KATANA_CODEC_ALEN_32;
296 + break;
297 + default:
298 + dev_err(codec->dev, "Bad frame size: %d\n",
299 + params_width(params));
300 + return -EINVAL;
301 + }
302 +
303 + switch (params_rate(params)) {
304 + case 44100:
305 + fmt |= KATANA_CODEC_RATE_44100;
306 + break;
307 + case 48000:
308 + fmt |= KATANA_CODEC_RATE_48000;
309 + break;
310 + case 88200:
311 + fmt |= KATANA_CODEC_RATE_88200;
312 + break;
313 + case 96000:
314 + fmt |= KATANA_CODEC_RATE_96000;
315 + break;
316 + case 176400:
317 + fmt |= KATANA_CODEC_RATE_176400;
318 + break;
319 + case 192000:
320 + fmt |= KATANA_CODEC_RATE_192000;
321 + break;
322 + case 352800:
323 + fmt |= KATANA_CODEC_RATE_352800;
324 + break;
325 + case 384000:
326 + fmt |= KATANA_CODEC_RATE_384000;
327 + break;
328 + default:
329 + dev_err(codec->dev, "Bad sample rate: %d\n",
330 + params_rate(params));
331 + return -EINVAL;
332 + }
333 +
334 + ret = regmap_write(katana_codec->regmap, KATANA_CODEC_FORMAT, fmt);
335 + if (ret != 0) {
336 + dev_err(codec->dev, "Failed to set format: %d\n", ret);
337 + return ret;
338 + }
339 + break;
340 +
341 + default:
342 + return -EINVAL;
343 + }
344 +
345 + return 0;
346 +}
347 +
348 +static int katana_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
349 +{
350 + struct snd_soc_codec *codec = dai->codec;
351 + struct katana_codec_priv *katana_codec = snd_soc_codec_get_drvdata(codec);
352 +
353 + katana_codec->fmt = fmt;
354 +
355 + return 0;
356 +}
357 +
358 +static const struct snd_soc_dai_ops katana_codec_dai_ops = {
359 + .hw_params = katana_codec_hw_params,
360 + .set_fmt = katana_codec_set_fmt,
361 +};
362 +
363 +static struct snd_soc_dai_driver katana_codec_dai = {
364 + .name = "allo-katana-codec",
365 + .playback = {
366 + .stream_name = "Playback",
367 + .channels_min = 2,
368 + .channels_max = 2,
369 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
370 + .rate_min = 44100,
371 + .rate_max = 384000,
372 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
373 + SNDRV_PCM_FMTBIT_S32_LE
374 + },
375 + .ops = &katana_codec_dai_ops,
376 +};
377 +
378 +static struct snd_soc_codec_driver katana_codec_codec_driver = {
379 + .idle_bias_off = false,
380 +
381 + .component_driver = {
382 + .controls = katana_codec_controls,
383 + .num_controls = ARRAY_SIZE(katana_codec_controls),
384 + },
385 +};
386 +
387 +static const struct regmap_range_cfg katana_codec_range = {
388 + .name = "Pages", .range_min = KATANA_CODEC_VIRT_BASE,
389 + .range_max = KATANA_CODEC_MAX_REGISTER,
390 + .selector_reg = KATANA_CODEC_PAGE,
391 + .selector_mask = 0xff,
392 + .window_start = 0, .window_len = 0x100,
393 +};
394 +
395 +const struct regmap_config katana_codec_regmap = {
396 + .reg_bits = 8,
397 + .val_bits = 8,
398 +
399 + .ranges = &katana_codec_range,
400 + .num_ranges = 1,
401 +
402 + .max_register = KATANA_CODEC_MAX_REGISTER,
403 + .readable_reg = katana_codec_readable_register,
404 + .reg_defaults = katana_codec_reg_defaults,
405 + .num_reg_defaults = ARRAY_SIZE(katana_codec_reg_defaults),
406 + .cache_type = REGCACHE_RBTREE,
407 +};
408 +
409 +static int allo_katana_codec_probe(struct i2c_client *i2c,
410 + const struct i2c_device_id *id)
411 +{
412 + struct regmap *regmap;
413 + struct regmap_config config = katana_codec_regmap;
414 + struct device *dev = &i2c->dev;
415 + struct katana_codec_priv *katana_codec;
416 + unsigned int chip_id = 0;
417 + int ret;
418 +
419 + regmap = devm_regmap_init_i2c(i2c, &config);
420 + if (IS_ERR(regmap))
421 + return PTR_ERR(regmap);
422 +
423 + katana_codec = devm_kzalloc(dev, sizeof(struct katana_codec_priv),
424 + GFP_KERNEL);
425 + if (!katana_codec)
426 + return -ENOMEM;
427 +
428 + dev_set_drvdata(dev, katana_codec);
429 + katana_codec->regmap = regmap;
430 +
431 + ret = regmap_read(regmap, KATANA_CODEC_CHIP_ID_REG, &chip_id);
432 + if ((ret != 0) || (chip_id != KATANA_CODEC_CHIP_ID)) {
433 + dev_err(dev, "Failed to read Chip or wrong Chip id: %d\n", ret);
434 + return ret;
435 + }
436 + regmap_update_bits(regmap, KATANA_CODEC_RESET, 0x01, 0x01);
437 + msleep(10);
438 +
439 + ret = snd_soc_register_codec(dev, &katana_codec_codec_driver,
440 + &katana_codec_dai, 1);
441 + if (ret != 0) {
442 + dev_err(dev, "failed to register codec: %d\n", ret);
443 + return ret;
444 + }
445 +
446 + return 0;
447 +}
448 +
449 +static int allo_katana_codec_remove(struct i2c_client *i2c)
450 +{
451 + snd_soc_unregister_codec(&i2c->dev);
452 + return 0;
453 +}
454 +
455 +static const struct i2c_device_id allo_katana_codec_id[] = {
456 + { "allo-katana-codec", },
457 + { }
458 +};
459 +MODULE_DEVICE_TABLE(i2c, allo_katana_codec_id);
460 +
461 +static const struct of_device_id allo_katana_codec_of_match[] = {
462 + { .compatible = "allo,allo-katana-codec", },
463 + { }
464 +};
465 +MODULE_DEVICE_TABLE(of, allo_katana_codec_of_match);
466 +
467 +static struct i2c_driver allo_katana_codec_driver = {
468 + .probe = allo_katana_codec_probe,
469 + .remove = allo_katana_codec_remove,
470 + .id_table = allo_katana_codec_id,
471 + .driver = {
472 + .name = "allo-katana-codec",
473 + .of_match_table = allo_katana_codec_of_match,
474 + },
475 +};
476 +
477 +module_i2c_driver(allo_katana_codec_driver);
478 +
479 +MODULE_DESCRIPTION("ASoC Allo Katana Codec Driver");
480 +MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>");
481 +MODULE_LICENSE("GPL v2");
482 +
483 --- a/sound/soc/bcm/allo-katana-dac.c
484 +++ /dev/null
485 @@ -1,102 +0,0 @@
486 -/*
487 - * ASoC Driver for KATANA DAC
488 - *
489 - * Author: Jaikumar <jaikumar@cem-solutions.net>
490 - * Copyright 2018
491 - *
492 - * This program is free software; you can redistribute it and/or
493 - * modify it under the terms of the GNU General Public License
494 - * version 2 as published by the Free Software Foundation.
495 - *
496 - * This program is distributed in the hope that it will be useful, but
497 - * WITHOUT ANY WARRANTY; without even the implied warranty of
498 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
499 - * General Public License for more details.
500 - */
501 -
502 -#include <linux/module.h>
503 -#include <linux/platform_device.h>
504 -
505 -#include <sound/core.h>
506 -#include <sound/pcm.h>
507 -#include <sound/pcm_params.h>
508 -#include <sound/soc.h>
509 -
510 -static struct snd_soc_dai_link snd_allo_katana_dac_dai[] = {
511 -{
512 - .name = "KATANA DAC",
513 - .stream_name = "KATANA DAC",
514 - .cpu_dai_name = "bcm2708-i2s.0",
515 - .codec_dai_name = "sabre-ess",
516 - .platform_name = "bcm2708-i2s.0",
517 - .codec_name = "sabre-ess.1-0030",
518 - .dai_fmt = SND_SOC_DAIFMT_I2S |
519 - SND_SOC_DAIFMT_NB_NF |
520 - SND_SOC_DAIFMT_CBM_CFM,
521 -},
522 -};
523 -
524 -/* audio machine driver */
525 -static struct snd_soc_card snd_allo_katana_dac = {
526 - .name = "snd_allo_katana_dac",
527 - .owner = THIS_MODULE,
528 - .dai_link = snd_allo_katana_dac_dai,
529 - .num_links = ARRAY_SIZE(snd_allo_katana_dac_dai),
530 -};
531 -
532 -static int snd_allo_katana_dac_probe(struct platform_device *pdev)
533 -{
534 - int ret = 0;
535 -
536 - snd_allo_katana_dac.dev = &pdev->dev;
537 -
538 - if (pdev->dev.of_node) {
539 - struct device_node *i2s_node;
540 - struct snd_soc_dai_link *dai = &snd_allo_katana_dac_dai[0];
541 -
542 - i2s_node = of_parse_phandle(pdev->dev.of_node,
543 - "i2s-controller", 0);
544 -
545 - if (i2s_node) {
546 - dai->cpu_dai_name = NULL;
547 - dai->cpu_of_node = i2s_node;
548 - dai->platform_name = NULL;
549 - dai->platform_of_node = i2s_node;
550 - }
551 - }
552 -
553 - ret = snd_soc_register_card(&snd_allo_katana_dac);
554 - if (ret && ret != -EPROBE_DEFER)
555 - dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
556 - ret);
557 -
558 - return ret;
559 -}
560 -
561 -static int snd_allo_katana_dac_remove(struct platform_device *pdev)
562 -{
563 - return snd_soc_unregister_card(&snd_allo_katana_dac);
564 -}
565 -
566 -static const struct of_device_id snd_allo_katana_dac_of_match[] = {
567 - { .compatible = "allo,katana-dac", },
568 - {},
569 -};
570 -MODULE_DEVICE_TABLE(of, snd_allo_katana_dac_of_match);
571 -
572 -static struct platform_driver snd_allo_katana_dac_driver = {
573 - .driver = {
574 - .name = "snd-katana-dac",
575 - .owner = THIS_MODULE,
576 - .of_match_table = snd_allo_katana_dac_of_match,
577 - },
578 - .probe = snd_allo_katana_dac_probe,
579 - .remove = snd_allo_katana_dac_remove,
580 -};
581 -
582 -module_platform_driver(snd_allo_katana_dac_driver);
583 -
584 -MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>");
585 -MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Katana DAC");
586 -MODULE_LICENSE("GPL v2");
587 -
588 --- a/sound/soc/codecs/Kconfig
589 +++ b/sound/soc/codecs/Kconfig
590 @@ -77,7 +77,6 @@ config SND_SOC_ALL_CODECS
591 select SND_SOC_ES8328_SPI if SPI_MASTER
592 select SND_SOC_ES8328_I2C if I2C
593 select SND_SOC_ES7134
594 - select SND_SOC_SABRE_ESS_I2C if I2C
595 select SND_SOC_GTM601
596 select SND_SOC_HDAC_HDMI
597 select SND_SOC_ICS43432
598 @@ -1187,13 +1186,4 @@ config SND_SOC_TPA6130A2
599 tristate "Texas Instruments TPA6130A2 headphone amplifier"
600 depends on I2C
601
602 -config SND_SOC_SABRE_ESS
603 - tristate
604 -
605 -config SND_SOC_SABRE_ESS_I2C
606 - tristate "Sabre SABRE ESS CODEC - I2C"
607 - depends on I2C
608 - select SND_SOC_SABRE_ESS
609 - select REGMAP_I2C
610 -
611 endmenu
612 --- a/sound/soc/codecs/Makefile
613 +++ b/sound/soc/codecs/Makefile
614 @@ -71,8 +71,6 @@ snd-soc-es8316-objs := es8316.o
615 snd-soc-es8328-objs := es8328.o
616 snd-soc-es8328-i2c-objs := es8328-i2c.o
617 snd-soc-es8328-spi-objs := es8328-spi.o
618 -snd-soc-sabre-ess-objs := sabre-ess.o
619 -snd-soc-sabre-ess-i2c-objs := sabre-ess-i2c.o
620 snd-soc-gtm601-objs := gtm601.o
621 snd-soc-hdac-hdmi-objs := hdac_hdmi.o
622 snd-soc-ics43432-objs := ics43432.o
623 @@ -315,8 +313,6 @@ obj-$(CONFIG_SND_SOC_ES8316) += snd-s
624 obj-$(CONFIG_SND_SOC_ES8328) += snd-soc-es8328.o
625 obj-$(CONFIG_SND_SOC_ES8328_I2C)+= snd-soc-es8328-i2c.o
626 obj-$(CONFIG_SND_SOC_ES8328_SPI)+= snd-soc-es8328-spi.o
627 -obj-$(CONFIG_SND_SOC_SABRE_ESS) += snd-soc-sabre-ess.o
628 -obj-$(CONFIG_SND_SOC_SABRE_ESS_I2C) += snd-soc-sabre-ess-i2c.o
629 obj-$(CONFIG_SND_SOC_GTM601) += snd-soc-gtm601.o
630 obj-$(CONFIG_SND_SOC_HDAC_HDMI) += snd-soc-hdac-hdmi.o
631 obj-$(CONFIG_SND_SOC_ICS43432) += snd-soc-ics43432.o
632 --- a/sound/soc/codecs/sabre-ess-i2c.c
633 +++ /dev/null
634 @@ -1,69 +0,0 @@
635 -/*
636 - * Driver for the SABRE ESS CODECs
637 - *
638 - * Author: Jaikumar <jaikumar@cem-solutions.net>
639 - * Copyright 2018
640 - *
641 - * This program is free software; you can redistribute it and/or
642 - * modify it under the terms of the GNU General Public License
643 - * version 2 as published by the Free Software Foundation.
644 - *
645 - * This program is distributed in the hope that it will be useful, but
646 - * WITHOUT ANY WARRANTY; without even the implied warranty of
647 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
648 - * General Public License for more details.
649 - */
650 -
651 -#include <linux/init.h>
652 -#include <linux/module.h>
653 -#include <linux/i2c.h>
654 -
655 -#include "sabre-ess.h"
656 -
657 -static int sabre_ess_i2c_probe(struct i2c_client *i2c,
658 - const struct i2c_device_id *id)
659 -{
660 - struct regmap *regmap;
661 - struct regmap_config config = sabre_ess_regmap;
662 -
663 - regmap = devm_regmap_init_i2c(i2c, &config);
664 - if (IS_ERR(regmap))
665 - return PTR_ERR(regmap);
666 -
667 - return sabre_ess_probe(&i2c->dev, regmap);
668 -}
669 -
670 -static int sabre_ess_i2c_remove(struct i2c_client *i2c)
671 -{
672 - sabre_ess_remove(&i2c->dev);
673 - return 0;
674 -}
675 -
676 -static const struct i2c_device_id sabre_ess_i2c_id[] = {
677 - { "sabre-ess", },
678 - { }
679 -};
680 -MODULE_DEVICE_TABLE(i2c, sabre_ess_i2c_id);
681 -
682 -static const struct of_device_id sabre_ess_of_match[] = {
683 - { .compatible = "saber,sabre-ess", },
684 - { }
685 -};
686 -MODULE_DEVICE_TABLE(of, sabre_ess_of_match);
687 -
688 -static struct i2c_driver sabre_ess_i2c_driver = {
689 - .probe = sabre_ess_i2c_probe,
690 - .remove = sabre_ess_i2c_remove,
691 - .id_table = sabre_ess_i2c_id,
692 - .driver = {
693 - .name = "sabre-ess",
694 - .of_match_table = sabre_ess_of_match,
695 - },
696 -};
697 -
698 -module_i2c_driver(sabre_ess_i2c_driver);
699 -
700 -MODULE_DESCRIPTION("ASoC SABRE ESS codec driver - I2C");
701 -MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>");
702 -MODULE_LICENSE("GPL v2");
703 -
704 --- a/sound/soc/codecs/sabre-ess.c
705 +++ /dev/null
706 @@ -1,300 +0,0 @@
707 -/*
708 - * Driver for the SABRE ESS CODEC
709 - *
710 - * Author: Jaikumar <jaikumar@cem-solutions.net>
711 - * Copyright 2018
712 - *
713 - * This program is free software; you can redistribute it and/or
714 - * modify it under the terms of the GNU General Public License
715 - * version 2 as published by the Free Software Foundation.
716 - *
717 - * This program is distributed in the hope that it will be useful, but
718 - * WITHOUT ANY WARRANTY; without even the implied warranty of
719 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
720 - * General Public License for more details.
721 - */
722 -
723 -
724 -#include <linux/init.h>
725 -#include <linux/module.h>
726 -#include <linux/clk.h>
727 -#include <linux/kernel.h>
728 -#include <linux/pm_runtime.h>
729 -#include <linux/regmap.h>
730 -#include <linux/regulator/consumer.h>
731 -#include <linux/gcd.h>
732 -#include <sound/soc.h>
733 -#include <sound/soc-dapm.h>
734 -#include <sound/pcm_params.h>
735 -#include <sound/tlv.h>
736 -
737 -#include "sabre-ess.h"
738 -
739 -struct sabre_ess_priv {
740 - struct regmap *regmap;
741 - int fmt;
742 -};
743 -
744 -static const struct reg_default sabre_ess_reg_defaults[] = {
745 - { SABRE_ESS_RESET, 0x00 },
746 - { SABRE_ESS_VOLUME_1, 0xF0 },
747 - { SABRE_ESS_VOLUME_2, 0xF0 },
748 - { SABRE_ESS_MUTE, 0x00 },
749 - { SABRE_ESS_DSP_PROGRAM, 0x04 },
750 - { SABRE_ESS_DEEMPHASIS, 0x00 },
751 - { SABRE_ESS_DOP, 0x01 },
752 - { SABRE_ESS_FORMAT, 0xb4 },
753 -};
754 -
755 -static const char * const sabre_ess_dsp_program_texts[] = {
756 - "Linear Phase Fast Roll-off Filter",
757 - "Linear Phase Slow Roll-off Filter",
758 - "Minimum Phase Fast Roll-off Filter",
759 - "Minimum Phase Slow Roll-off Filter",
760 - "Apodizing Fast Roll-off Filter",
761 - "Corrected Minimum Phase Fast Roll-off Filter",
762 - "Brick Wall Filter",
763 -};
764 -
765 -static const unsigned int sabre_ess_dsp_program_values[] = {
766 - 0,
767 - 1,
768 - 2,
769 - 3,
770 - 4,
771 - 6,
772 - 7,
773 -};
774 -
775 -static SOC_VALUE_ENUM_SINGLE_DECL(sabre_ess_dsp_program,
776 - SABRE_ESS_DSP_PROGRAM, 0, 0x07,
777 - sabre_ess_dsp_program_texts,
778 - sabre_ess_dsp_program_values);
779 -
780 -static const char * const sabre_ess_deemphasis_texts[] = {
781 - "Bypass",
782 - "32kHz",
783 - "44.1kHz",
784 - "48kHz",
785 -};
786 -
787 -static const unsigned int sabre_ess_deemphasis_values[] = {
788 - 0,
789 - 1,
790 - 2,
791 - 3,
792 -};
793 -
794 -static SOC_VALUE_ENUM_SINGLE_DECL(sabre_ess_deemphasis,
795 - SABRE_ESS_DEEMPHASIS, 0, 0x03,
796 - sabre_ess_deemphasis_texts,
797 - sabre_ess_deemphasis_values);
798 -
799 -static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12700, 0);
800 -
801 -static const struct snd_kcontrol_new sabre_ess_controls[] = {
802 - SOC_DOUBLE_R_TLV("Master Playback Volume", SABRE_ESS_VOLUME_1,
803 - SABRE_ESS_VOLUME_2, 0, 255, 1, master_tlv),
804 - SOC_DOUBLE("Master Playback Switch", SABRE_ESS_MUTE, 0, 0, 1, 1),
805 - SOC_ENUM("DSP Program Route", sabre_ess_dsp_program),
806 - SOC_ENUM("Deemphasis Route", sabre_ess_deemphasis),
807 - SOC_SINGLE("DoP Playback Switch", SABRE_ESS_DOP, 0, 1, 1)
808 -};
809 -
810 -static bool sabre_ess_readable_register(struct device *dev, unsigned int reg)
811 -{
812 - switch (reg) {
813 - case SABRE_ESS_CHIP_ID_REG:
814 - return true;
815 - default:
816 - return reg < 0xff;
817 - }
818 -}
819 -
820 -static int sabre_ess_hw_params(struct snd_pcm_substream *substream,
821 - struct snd_pcm_hw_params *params,
822 - struct snd_soc_dai *dai)
823 -{
824 - struct snd_soc_codec *codec = dai->codec;
825 - struct sabre_ess_priv *sabre_ess = snd_soc_codec_get_drvdata(codec);
826 - int fmt = 0;
827 - int ret;
828 -
829 - dev_dbg(codec->dev, "hw_params %u Hz, %u channels\n",
830 - params_rate(params),
831 - params_channels(params));
832 -
833 - switch (sabre_ess->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
834 - case SND_SOC_DAIFMT_CBM_CFM: // master
835 - if (params_channels(params) == 2)
836 - fmt = SABRE_ESS_CHAN_STEREO;
837 - else
838 - fmt = SABRE_ESS_CHAN_MONO;
839 -
840 - switch (params_width(params)) {
841 - case 16:
842 - fmt |= SABRE_ESS_ALEN_16;
843 - break;
844 - case 24:
845 - fmt |= SABRE_ESS_ALEN_24;
846 - break;
847 - case 32:
848 - fmt |= SABRE_ESS_ALEN_32;
849 - break;
850 - default:
851 - dev_err(codec->dev, "Bad frame size: %d\n",
852 - params_width(params));
853 - return -EINVAL;
854 - }
855 -
856 - switch (params_rate(params)) {
857 - case 44100:
858 - fmt |= SABRE_ESS_RATE_44100;
859 - break;
860 - case 48000:
861 - fmt |= SABRE_ESS_RATE_48000;
862 - break;
863 - case 88200:
864 - fmt |= SABRE_ESS_RATE_88200;
865 - break;
866 - case 96000:
867 - fmt |= SABRE_ESS_RATE_96000;
868 - break;
869 - case 176400:
870 - fmt |= SABRE_ESS_RATE_176400;
871 - break;
872 - case 192000:
873 - fmt |= SABRE_ESS_RATE_192000;
874 - break;
875 - case 352800:
876 - fmt |= SABRE_ESS_RATE_352800;
877 - break;
878 - case 384000:
879 - fmt |= SABRE_ESS_RATE_384000;
880 - break;
881 - default:
882 - dev_err(codec->dev, "Bad sample rate: %d\n",
883 - params_rate(params));
884 - return -EINVAL;
885 - }
886 -
887 - ret = regmap_write(sabre_ess->regmap, SABRE_ESS_FORMAT, fmt);
888 - if (ret != 0) {
889 - dev_err(codec->dev, "Failed to set format: %d\n", ret);
890 - return ret;
891 - }
892 - break;
893 -
894 - default:
895 - return -EINVAL;
896 - }
897 -
898 - return 0;
899 -}
900 -
901 -static int sabre_ess_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
902 -{
903 - struct snd_soc_codec *codec = dai->codec;
904 - struct sabre_ess_priv *sabre_ess = snd_soc_codec_get_drvdata(codec);
905 -
906 - sabre_ess->fmt = fmt;
907 -
908 - return 0;
909 -}
910 -
911 -static const struct snd_soc_dai_ops sabre_ess_dai_ops = {
912 - .hw_params = sabre_ess_hw_params,
913 - .set_fmt = sabre_ess_set_fmt,
914 -};
915 -
916 -static struct snd_soc_dai_driver sabre_ess_dai = {
917 - .name = "sabre-ess",
918 - .playback = {
919 - .stream_name = "Playback",
920 - .channels_min = 2,
921 - .channels_max = 2,
922 - .rates = SNDRV_PCM_RATE_CONTINUOUS,
923 - .rate_min = 44100,
924 - .rate_max = 384000,
925 - .formats = SNDRV_PCM_FMTBIT_S16_LE |
926 - SNDRV_PCM_FMTBIT_S32_LE
927 - },
928 - .ops = &sabre_ess_dai_ops,
929 -};
930 -
931 -static struct snd_soc_codec_driver sabre_ess_codec_driver = {
932 - .idle_bias_off = false,
933 -
934 - .component_driver = {
935 - .controls = sabre_ess_controls,
936 - .num_controls = ARRAY_SIZE(sabre_ess_controls),
937 - },
938 -};
939 -
940 -static const struct regmap_range_cfg sabre_ess_range = {
941 - .name = "Pages", .range_min = SABRE_ESS_VIRT_BASE,
942 - .range_max = SABRE_ESS_MAX_REGISTER,
943 - .selector_reg = SABRE_ESS_PAGE,
944 - .selector_mask = 0xff,
945 - .window_start = 0, .window_len = 0x100,
946 -};
947 -
948 -const struct regmap_config sabre_ess_regmap = {
949 - .reg_bits = 8,
950 - .val_bits = 8,
951 -
952 - .ranges = &sabre_ess_range,
953 - .num_ranges = 1,
954 -
955 - .max_register = SABRE_ESS_MAX_REGISTER,
956 - .readable_reg = sabre_ess_readable_register,
957 - .reg_defaults = sabre_ess_reg_defaults,
958 - .num_reg_defaults = ARRAY_SIZE(sabre_ess_reg_defaults),
959 - .cache_type = REGCACHE_RBTREE,
960 -};
961 -EXPORT_SYMBOL_GPL(sabre_ess_regmap);
962 -
963 -int sabre_ess_probe(struct device *dev, struct regmap *regmap)
964 -{
965 - struct sabre_ess_priv *sabre_ess;
966 - unsigned int chip_id = 0;
967 - int ret;
968 -
969 - sabre_ess = devm_kzalloc(dev, sizeof(struct sabre_ess_priv),
970 - GFP_KERNEL);
971 - if (!sabre_ess)
972 - return -ENOMEM;
973 -
974 - dev_set_drvdata(dev, sabre_ess);
975 - sabre_ess->regmap = regmap;
976 -
977 - ret = regmap_read(regmap, SABRE_ESS_CHIP_ID_REG, &chip_id);
978 - if ((ret != 0) || (chip_id != SABRE_ESS_CHIP_ID)) {
979 - dev_err(dev, "Failed to read Chip or wrong Chip id: %d\n", ret);
980 - return ret;
981 - }
982 - regmap_update_bits(regmap, SABRE_ESS_RESET, 0x01, 0x01);
983 - msleep(10);
984 -
985 - ret = snd_soc_register_codec(dev, &sabre_ess_codec_driver,
986 - &sabre_ess_dai, 1);
987 - if (ret != 0) {
988 - dev_err(dev, "failed to register codec: %d\n", ret);
989 - return ret;
990 - }
991 -
992 - return 0;
993 -}
994 -EXPORT_SYMBOL_GPL(sabre_ess_probe);
995 -
996 -void sabre_ess_remove(struct device *dev)
997 -{
998 - snd_soc_unregister_codec(dev);
999 - pm_runtime_disable(dev);
1000 -}
1001 -EXPORT_SYMBOL_GPL(sabre_ess_remove);
1002 -
1003 -MODULE_DESCRIPTION("ASoC SABRE ESS codec driver");
1004 -MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>");
1005 -MODULE_LICENSE("GPL v2");
1006 -
1007 --- a/sound/soc/codecs/sabre-ess.h
1008 +++ /dev/null
1009 @@ -1,62 +0,0 @@
1010 -/*
1011 - * Driver for the SABRE ESS CODEC
1012 - *
1013 - * Author: Jaikumar <jaikumar@cem-solutions.net>
1014 - * Copyright 2018
1015 - *
1016 - * This program is free software; you can redistribute it and/or
1017 - * modify it under the terms of the GNU General Public License
1018 - * version 2 as published by the Free Software Foundation.
1019 - *
1020 - * This program is distributed in the hope that it will be useful, but
1021 - * WITHOUT ANY WARRANTY; without even the implied warranty of
1022 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1023 - * General Public License for more details.
1024 - */
1025 -
1026 -#ifndef _SND_SOC_SABRE_ESS_
1027 -#define _SND_SOC_SABRE_ESS_
1028 -
1029 -#include <linux/pm.h>
1030 -#include <linux/regmap.h>
1031 -
1032 -#define SABRE_ESS_CHIP_ID 0x30
1033 -#define SABRE_ESS_VIRT_BASE 0x100
1034 -#define SABRE_ESS_PAGE 0
1035 -
1036 -#define SABRE_ESS_CHIP_ID_REG (SABRE_ESS_VIRT_BASE + 0)
1037 -#define SABRE_ESS_RESET (SABRE_ESS_VIRT_BASE + 1)
1038 -#define SABRE_ESS_VOLUME_1 (SABRE_ESS_VIRT_BASE + 2)
1039 -#define SABRE_ESS_VOLUME_2 (SABRE_ESS_VIRT_BASE + 3)
1040 -#define SABRE_ESS_MUTE (SABRE_ESS_VIRT_BASE + 4)
1041 -#define SABRE_ESS_DSP_PROGRAM (SABRE_ESS_VIRT_BASE + 5)
1042 -#define SABRE_ESS_DEEMPHASIS (SABRE_ESS_VIRT_BASE + 6)
1043 -#define SABRE_ESS_DOP (SABRE_ESS_VIRT_BASE + 7)
1044 -#define SABRE_ESS_FORMAT (SABRE_ESS_VIRT_BASE + 8)
1045 -#define SABRE_ESS_COMMAND (SABRE_ESS_VIRT_BASE + 9)
1046 -#define SABRE_ESS_MAX_REGISTER (SABRE_ESS_VIRT_BASE + 9)
1047 -
1048 -#define SABRE_ESS_FMT 0xff
1049 -#define SABRE_ESS_CHAN_MONO 0x00
1050 -#define SABRE_ESS_CHAN_STEREO 0x80
1051 -#define SABRE_ESS_ALEN_16 0x10
1052 -#define SABRE_ESS_ALEN_24 0x20
1053 -#define SABRE_ESS_ALEN_32 0x30
1054 -#define SABRE_ESS_RATE_11025 0x01
1055 -#define SABRE_ESS_RATE_22050 0x02
1056 -#define SABRE_ESS_RATE_32000 0x03
1057 -#define SABRE_ESS_RATE_44100 0x04
1058 -#define SABRE_ESS_RATE_48000 0x05
1059 -#define SABRE_ESS_RATE_88200 0x06
1060 -#define SABRE_ESS_RATE_96000 0x07
1061 -#define SABRE_ESS_RATE_176400 0x08
1062 -#define SABRE_ESS_RATE_192000 0x09
1063 -#define SABRE_ESS_RATE_352800 0x0a
1064 -#define SABRE_ESS_RATE_384000 0x0b
1065 -
1066 -extern const struct regmap_config sabre_ess_regmap;
1067 -
1068 -int sabre_ess_probe(struct device *dev, struct regmap *regmap);
1069 -void sabre_ess_remove(struct device *dev);
1070 -
1071 -#endif /* _SND_SOC_SABRE_ESS_ */