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
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
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
28 * Definitions for Allo Katana DAC boards
30 - * NB. The Katana DAC board contains SABER DAC.
38 + #sound-dai-cells = <0>;
41 + cpu_endpoint: endpoint {
42 + remote-endpoint = <&codec_endpoint>;
43 + bitclock-master = <&codec_endpoint>;
44 + frame-master = <&codec_endpoint>;
56 + allo-katana-codec@30 {
57 #sound-dai-cells = <0>;
58 - compatible = "saber,sabre-ess";
59 + compatible = "allo,allo-katana-codec";
63 + codec_endpoint: endpoint {
64 + remote-endpoint = <&cpu_endpoint>;
73 katana_dac: __overlay__ {
74 - compatible = "allo,katana-dac";
75 - i2s-controller = <&i2s>;
76 + compatible = "audio-graph-card";
77 + label = "Allo Katana";
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
94 + select SND_AUDIO_GRAPH_CARD
96 Say Y or M if you want to add support for Allo Katana DAC.
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
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
118 +++ b/sound/soc/bcm/allo-katana-codec.c
121 + * Driver for the ALLO KATANA CODEC
123 + * Author: Jaikumar <jaikumar@cem-solutions.net>
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.
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.
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>
151 +#define KATANA_CODEC_CHIP_ID 0x30
152 +#define KATANA_CODEC_VIRT_BASE 0x100
153 +#define KATANA_CODEC_PAGE 0
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)
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
186 +struct katana_codec_priv {
187 + struct regmap *regmap;
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 },
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",
212 +static const unsigned int katana_codec_dsp_program_values[] = {
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);
227 +static const char * const katana_codec_deemphasis_texts[] = {
234 +static const unsigned int katana_codec_deemphasis_values[] = {
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);
246 +static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12700, 0);
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)
257 +static bool katana_codec_readable_register(struct device *dev, unsigned int reg)
260 + case KATANA_CODEC_CHIP_ID_REG:
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)
271 + struct snd_soc_codec *codec = dai->codec;
272 + struct katana_codec_priv *katana_codec = snd_soc_codec_get_drvdata(codec);
276 + dev_dbg(codec->dev, "hw_params %u Hz, %u channels\n",
277 + params_rate(params),
278 + params_channels(params));
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;
285 + fmt = KATANA_CODEC_CHAN_MONO;
287 + switch (params_width(params)) {
289 + fmt |= KATANA_CODEC_ALEN_16;
292 + fmt |= KATANA_CODEC_ALEN_24;
295 + fmt |= KATANA_CODEC_ALEN_32;
298 + dev_err(codec->dev, "Bad frame size: %d\n",
299 + params_width(params));
303 + switch (params_rate(params)) {
305 + fmt |= KATANA_CODEC_RATE_44100;
308 + fmt |= KATANA_CODEC_RATE_48000;
311 + fmt |= KATANA_CODEC_RATE_88200;
314 + fmt |= KATANA_CODEC_RATE_96000;
317 + fmt |= KATANA_CODEC_RATE_176400;
320 + fmt |= KATANA_CODEC_RATE_192000;
323 + fmt |= KATANA_CODEC_RATE_352800;
326 + fmt |= KATANA_CODEC_RATE_384000;
329 + dev_err(codec->dev, "Bad sample rate: %d\n",
330 + params_rate(params));
334 + ret = regmap_write(katana_codec->regmap, KATANA_CODEC_FORMAT, fmt);
336 + dev_err(codec->dev, "Failed to set format: %d\n", ret);
348 +static int katana_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
350 + struct snd_soc_codec *codec = dai->codec;
351 + struct katana_codec_priv *katana_codec = snd_soc_codec_get_drvdata(codec);
353 + katana_codec->fmt = fmt;
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,
363 +static struct snd_soc_dai_driver katana_codec_dai = {
364 + .name = "allo-katana-codec",
366 + .stream_name = "Playback",
369 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
371 + .rate_max = 384000,
372 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
373 + SNDRV_PCM_FMTBIT_S32_LE
375 + .ops = &katana_codec_dai_ops,
378 +static struct snd_soc_codec_driver katana_codec_codec_driver = {
379 + .idle_bias_off = false,
381 + .component_driver = {
382 + .controls = katana_codec_controls,
383 + .num_controls = ARRAY_SIZE(katana_codec_controls),
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,
395 +const struct regmap_config katana_codec_regmap = {
399 + .ranges = &katana_codec_range,
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,
409 +static int allo_katana_codec_probe(struct i2c_client *i2c,
410 + const struct i2c_device_id *id)
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;
419 + regmap = devm_regmap_init_i2c(i2c, &config);
420 + if (IS_ERR(regmap))
421 + return PTR_ERR(regmap);
423 + katana_codec = devm_kzalloc(dev, sizeof(struct katana_codec_priv),
428 + dev_set_drvdata(dev, katana_codec);
429 + katana_codec->regmap = regmap;
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);
436 + regmap_update_bits(regmap, KATANA_CODEC_RESET, 0x01, 0x01);
439 + ret = snd_soc_register_codec(dev, &katana_codec_codec_driver,
440 + &katana_codec_dai, 1);
442 + dev_err(dev, "failed to register codec: %d\n", ret);
449 +static int allo_katana_codec_remove(struct i2c_client *i2c)
451 + snd_soc_unregister_codec(&i2c->dev);
455 +static const struct i2c_device_id allo_katana_codec_id[] = {
456 + { "allo-katana-codec", },
459 +MODULE_DEVICE_TABLE(i2c, allo_katana_codec_id);
461 +static const struct of_device_id allo_katana_codec_of_match[] = {
462 + { .compatible = "allo,allo-katana-codec", },
465 +MODULE_DEVICE_TABLE(of, allo_katana_codec_of_match);
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,
472 + .name = "allo-katana-codec",
473 + .of_match_table = allo_katana_codec_of_match,
477 +module_i2c_driver(allo_katana_codec_driver);
479 +MODULE_DESCRIPTION("ASoC Allo Katana Codec Driver");
480 +MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>");
481 +MODULE_LICENSE("GPL v2");
483 --- a/sound/soc/bcm/allo-katana-dac.c
487 - * ASoC Driver for KATANA DAC
489 - * Author: Jaikumar <jaikumar@cem-solutions.net>
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.
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.
502 -#include <linux/module.h>
503 -#include <linux/platform_device.h>
505 -#include <sound/core.h>
506 -#include <sound/pcm.h>
507 -#include <sound/pcm_params.h>
508 -#include <sound/soc.h>
510 -static struct snd_soc_dai_link snd_allo_katana_dac_dai[] = {
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,
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),
532 -static int snd_allo_katana_dac_probe(struct platform_device *pdev)
536 - snd_allo_katana_dac.dev = &pdev->dev;
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];
542 - i2s_node = of_parse_phandle(pdev->dev.of_node,
543 - "i2s-controller", 0);
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;
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",
561 -static int snd_allo_katana_dac_remove(struct platform_device *pdev)
563 - return snd_soc_unregister_card(&snd_allo_katana_dac);
566 -static const struct of_device_id snd_allo_katana_dac_of_match[] = {
567 - { .compatible = "allo,katana-dac", },
570 -MODULE_DEVICE_TABLE(of, snd_allo_katana_dac_of_match);
572 -static struct platform_driver snd_allo_katana_dac_driver = {
574 - .name = "snd-katana-dac",
575 - .owner = THIS_MODULE,
576 - .of_match_table = snd_allo_katana_dac_of_match,
578 - .probe = snd_allo_katana_dac_probe,
579 - .remove = snd_allo_katana_dac_remove,
582 -module_platform_driver(snd_allo_katana_dac_driver);
584 -MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>");
585 -MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Katana DAC");
586 -MODULE_LICENSE("GPL v2");
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"
602 -config SND_SOC_SABRE_ESS
605 -config SND_SOC_SABRE_ESS_I2C
606 - tristate "Sabre SABRE ESS CODEC - I2C"
608 - select SND_SOC_SABRE_ESS
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
636 - * Driver for the SABRE ESS CODECs
638 - * Author: Jaikumar <jaikumar@cem-solutions.net>
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.
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.
651 -#include <linux/init.h>
652 -#include <linux/module.h>
653 -#include <linux/i2c.h>
655 -#include "sabre-ess.h"
657 -static int sabre_ess_i2c_probe(struct i2c_client *i2c,
658 - const struct i2c_device_id *id)
660 - struct regmap *regmap;
661 - struct regmap_config config = sabre_ess_regmap;
663 - regmap = devm_regmap_init_i2c(i2c, &config);
664 - if (IS_ERR(regmap))
665 - return PTR_ERR(regmap);
667 - return sabre_ess_probe(&i2c->dev, regmap);
670 -static int sabre_ess_i2c_remove(struct i2c_client *i2c)
672 - sabre_ess_remove(&i2c->dev);
676 -static const struct i2c_device_id sabre_ess_i2c_id[] = {
680 -MODULE_DEVICE_TABLE(i2c, sabre_ess_i2c_id);
682 -static const struct of_device_id sabre_ess_of_match[] = {
683 - { .compatible = "saber,sabre-ess", },
686 -MODULE_DEVICE_TABLE(of, sabre_ess_of_match);
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,
693 - .name = "sabre-ess",
694 - .of_match_table = sabre_ess_of_match,
698 -module_i2c_driver(sabre_ess_i2c_driver);
700 -MODULE_DESCRIPTION("ASoC SABRE ESS codec driver - I2C");
701 -MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>");
702 -MODULE_LICENSE("GPL v2");
704 --- a/sound/soc/codecs/sabre-ess.c
708 - * Driver for the SABRE ESS CODEC
710 - * Author: Jaikumar <jaikumar@cem-solutions.net>
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.
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.
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>
737 -#include "sabre-ess.h"
739 -struct sabre_ess_priv {
740 - struct regmap *regmap;
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 },
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",
765 -static const unsigned int sabre_ess_dsp_program_values[] = {
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);
780 -static const char * const sabre_ess_deemphasis_texts[] = {
787 -static const unsigned int sabre_ess_deemphasis_values[] = {
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);
799 -static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(master_tlv, -12700, 0);
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)
810 -static bool sabre_ess_readable_register(struct device *dev, unsigned int reg)
813 - case SABRE_ESS_CHIP_ID_REG:
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)
824 - struct snd_soc_codec *codec = dai->codec;
825 - struct sabre_ess_priv *sabre_ess = snd_soc_codec_get_drvdata(codec);
829 - dev_dbg(codec->dev, "hw_params %u Hz, %u channels\n",
830 - params_rate(params),
831 - params_channels(params));
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;
838 - fmt = SABRE_ESS_CHAN_MONO;
840 - switch (params_width(params)) {
842 - fmt |= SABRE_ESS_ALEN_16;
845 - fmt |= SABRE_ESS_ALEN_24;
848 - fmt |= SABRE_ESS_ALEN_32;
851 - dev_err(codec->dev, "Bad frame size: %d\n",
852 - params_width(params));
856 - switch (params_rate(params)) {
858 - fmt |= SABRE_ESS_RATE_44100;
861 - fmt |= SABRE_ESS_RATE_48000;
864 - fmt |= SABRE_ESS_RATE_88200;
867 - fmt |= SABRE_ESS_RATE_96000;
870 - fmt |= SABRE_ESS_RATE_176400;
873 - fmt |= SABRE_ESS_RATE_192000;
876 - fmt |= SABRE_ESS_RATE_352800;
879 - fmt |= SABRE_ESS_RATE_384000;
882 - dev_err(codec->dev, "Bad sample rate: %d\n",
883 - params_rate(params));
887 - ret = regmap_write(sabre_ess->regmap, SABRE_ESS_FORMAT, fmt);
889 - dev_err(codec->dev, "Failed to set format: %d\n", ret);
901 -static int sabre_ess_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
903 - struct snd_soc_codec *codec = dai->codec;
904 - struct sabre_ess_priv *sabre_ess = snd_soc_codec_get_drvdata(codec);
906 - sabre_ess->fmt = fmt;
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,
916 -static struct snd_soc_dai_driver sabre_ess_dai = {
917 - .name = "sabre-ess",
919 - .stream_name = "Playback",
922 - .rates = SNDRV_PCM_RATE_CONTINUOUS,
924 - .rate_max = 384000,
925 - .formats = SNDRV_PCM_FMTBIT_S16_LE |
926 - SNDRV_PCM_FMTBIT_S32_LE
928 - .ops = &sabre_ess_dai_ops,
931 -static struct snd_soc_codec_driver sabre_ess_codec_driver = {
932 - .idle_bias_off = false,
934 - .component_driver = {
935 - .controls = sabre_ess_controls,
936 - .num_controls = ARRAY_SIZE(sabre_ess_controls),
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,
948 -const struct regmap_config sabre_ess_regmap = {
952 - .ranges = &sabre_ess_range,
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,
961 -EXPORT_SYMBOL_GPL(sabre_ess_regmap);
963 -int sabre_ess_probe(struct device *dev, struct regmap *regmap)
965 - struct sabre_ess_priv *sabre_ess;
966 - unsigned int chip_id = 0;
969 - sabre_ess = devm_kzalloc(dev, sizeof(struct sabre_ess_priv),
974 - dev_set_drvdata(dev, sabre_ess);
975 - sabre_ess->regmap = regmap;
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);
982 - regmap_update_bits(regmap, SABRE_ESS_RESET, 0x01, 0x01);
985 - ret = snd_soc_register_codec(dev, &sabre_ess_codec_driver,
986 - &sabre_ess_dai, 1);
988 - dev_err(dev, "failed to register codec: %d\n", ret);
994 -EXPORT_SYMBOL_GPL(sabre_ess_probe);
996 -void sabre_ess_remove(struct device *dev)
998 - snd_soc_unregister_codec(dev);
999 - pm_runtime_disable(dev);
1001 -EXPORT_SYMBOL_GPL(sabre_ess_remove);
1003 -MODULE_DESCRIPTION("ASoC SABRE ESS codec driver");
1004 -MODULE_AUTHOR("Jaikumar <jaikumar@cem-solutions.net>");
1005 -MODULE_LICENSE("GPL v2");
1007 --- a/sound/soc/codecs/sabre-ess.h
1011 - * Driver for the SABRE ESS CODEC
1013 - * Author: Jaikumar <jaikumar@cem-solutions.net>
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.
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.
1026 -#ifndef _SND_SOC_SABRE_ESS_
1027 -#define _SND_SOC_SABRE_ESS_
1029 -#include <linux/pm.h>
1030 -#include <linux/regmap.h>
1032 -#define SABRE_ESS_CHIP_ID 0x30
1033 -#define SABRE_ESS_VIRT_BASE 0x100
1034 -#define SABRE_ESS_PAGE 0
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)
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
1066 -extern const struct regmap_config sabre_ess_regmap;
1068 -int sabre_ess_probe(struct device *dev, struct regmap *regmap);
1069 -void sabre_ess_remove(struct device *dev);
1071 -#endif /* _SND_SOC_SABRE_ESS_ */