mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-25 16:31:13 +00:00
7d7aa2fd92
This change makes the names of Broadcom targets consistent by using the common notation based on SoC/CPU ID (which is used internally anyway), bcmXXXX instead of brcmXXXX. This is even used for target TITLE in make menuconfig already, only the short target name used brcm so far. Despite, since subtargets range from bcm2708 to bcm2711, it seems appropriate to use bcm27xx instead of bcm2708 (again, as already done for BOARDNAME). This also renames the packages brcm2708-userland and brcm2708-gpu-fw. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de> Acked-by: Álvaro Fernández Rojas <noltari@gmail.com>
762 lines
21 KiB
Diff
762 lines
21 KiB
Diff
From c667b06f616d5dec68469ac73764abd5bcb1d694 Mon Sep 17 00:00:00 2001
|
|
From: FERHAT Nicolas <contact@audiophonics.fr>
|
|
Date: Fri, 5 Apr 2019 13:06:42 +0100
|
|
Subject: [PATCH] Audiophonics I-Sabre 9038Q2M DAC driver
|
|
|
|
Signed-off-by: Audiophonics <contact@audiophonics.fr>
|
|
---
|
|
arch/arm/boot/dts/overlays/Makefile | 1 +
|
|
arch/arm/boot/dts/overlays/README | 6 +
|
|
.../boot/dts/overlays/i-sabre-q2m-overlay.dts | 39 ++
|
|
sound/soc/bcm/Kconfig | 7 +
|
|
sound/soc/bcm/Makefile | 2 +
|
|
sound/soc/bcm/i-sabre-q2m.c | 157 +++++++
|
|
sound/soc/codecs/Kconfig | 5 +
|
|
sound/soc/codecs/Makefile | 2 +
|
|
sound/soc/codecs/i-sabre-codec.c | 392 ++++++++++++++++++
|
|
sound/soc/codecs/i-sabre-codec.h | 42 ++
|
|
13 files changed, 656 insertions(+)
|
|
create mode 100644 arch/arm/boot/dts/overlays/i-sabre-q2m-overlay.dts
|
|
create mode 100644 sound/soc/bcm/i-sabre-q2m.c
|
|
create mode 100644 sound/soc/codecs/i-sabre-codec.c
|
|
create mode 100644 sound/soc/codecs/i-sabre-codec.h
|
|
|
|
--- a/arch/arm/boot/dts/overlays/Makefile
|
|
+++ b/arch/arm/boot/dts/overlays/Makefile
|
|
@@ -55,6 +55,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
|
|
hy28a.dtbo \
|
|
hy28b.dtbo \
|
|
hy28b-2017.dtbo \
|
|
+ i-sabre-q2m.dtbo \
|
|
i2c-bcm2708.dtbo \
|
|
i2c-gpio.dtbo \
|
|
i2c-mux.dtbo \
|
|
--- a/arch/arm/boot/dts/overlays/README
|
|
+++ b/arch/arm/boot/dts/overlays/README
|
|
@@ -869,6 +869,12 @@ Params: speed Display
|
|
ledgpio GPIO used to control backlight
|
|
|
|
|
|
+Name: i-sabre-q2m
|
|
+Info: Configures the Audiophonics I-SABRE Q2M DAC
|
|
+Load: dtoverlay=i-sabre-q2m
|
|
+Params: <None>
|
|
+
|
|
+
|
|
Name: i2c-bcm2708
|
|
Info: Fall back to the i2c_bcm2708 driver for the i2c_arm bus.
|
|
Load: dtoverlay=i2c-bcm2708
|
|
--- /dev/null
|
|
+++ b/arch/arm/boot/dts/overlays/i-sabre-q2m-overlay.dts
|
|
@@ -0,0 +1,39 @@
|
|
+// Definitions for I-Sabre Q2M
|
|
+/dts-v1/;
|
|
+/plugin/;
|
|
+
|
|
+/ {
|
|
+ compatible = "brcm,bcm2708";
|
|
+
|
|
+ fragment@0 {
|
|
+ target = <&sound>;
|
|
+ frag0: __overlay__ {
|
|
+ compatible = "audiophonics,i-sabre-q2m";
|
|
+ i2s-controller = <&i2s>;
|
|
+ status = "okay";
|
|
+ };
|
|
+ };
|
|
+
|
|
+ fragment@1 {
|
|
+ target = <&i2s>;
|
|
+ __overlay__ {
|
|
+ status = "okay";
|
|
+ };
|
|
+ };
|
|
+
|
|
+ fragment@2 {
|
|
+ target = <&i2c1>;
|
|
+ __overlay__ {
|
|
+ #address-cells = <1>;
|
|
+ #size-cells = <0>;
|
|
+ status = "okay";
|
|
+
|
|
+ i-sabre-codec@48 {
|
|
+ #sound-dai-cells = <0>;
|
|
+ compatible = "audiophonics,i-sabre-codec";
|
|
+ reg = <0x48>;
|
|
+ status = "okay";
|
|
+ };
|
|
+ };
|
|
+ };
|
|
+};
|
|
--- a/sound/soc/bcm/Kconfig
|
|
+++ b/sound/soc/bcm/Kconfig
|
|
@@ -123,6 +123,13 @@ config SND_BCM2708_SOC_IQAUDIO_DIGI
|
|
help
|
|
Say Y or M if you want to add support for IQAudIO Digital IO board.
|
|
|
|
+config SND_BCM2708_SOC_I_SABRE_Q2M
|
|
+ tristate "Support for Audiophonics I-Sabre Q2M DAC"
|
|
+ depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
|
|
+ select SND_SOC_I_SABRE_CODEC
|
|
+ help
|
|
+ Say Y or M if you want to add support for Audiophonics I-SABRE Q2M DAC
|
|
+
|
|
config SND_BCM2708_SOC_ADAU1977_ADC
|
|
tristate "Support for ADAU1977 ADC"
|
|
depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
|
|
--- a/sound/soc/bcm/Makefile
|
|
+++ b/sound/soc/bcm/Makefile
|
|
@@ -19,6 +19,7 @@ snd-soc-justboom-dac-objs := justboom-da
|
|
snd-soc-rpi-cirrus-objs := rpi-cirrus.o
|
|
snd-soc-rpi-proto-objs := rpi-proto.o
|
|
snd-soc-iqaudio-dac-objs := iqaudio-dac.o
|
|
+ snd-soc-i-sabre-q2m-objs := i-sabre-q2m.o
|
|
snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
|
|
snd-soc-audioinjector-octo-soundcard-objs := audioinjector-octo-soundcard.o
|
|
snd-soc-audiosense-pi-objs := audiosense-pi.o
|
|
@@ -42,6 +43,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DA
|
|
obj-$(CONFIG_SND_BCM2708_SOC_RPI_CIRRUS) += snd-soc-rpi-cirrus.o
|
|
obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
|
|
obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
|
|
+ obj-$(CONFIG_SND_BCM2708_SOC_I_SABRE_Q2M) += snd-soc-i-sabre-q2m.o
|
|
obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
|
|
obj-$(CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD) += snd-soc-audioinjector-octo-soundcard.o
|
|
obj-$(CONFIG_SND_AUDIOSENSE_PI) += snd-soc-audiosense-pi.o
|
|
--- /dev/null
|
|
+++ b/sound/soc/bcm/i-sabre-q2m.c
|
|
@@ -0,0 +1,157 @@
|
|
+/*
|
|
+ * ASoC Driver for I-Sabre Q2M
|
|
+ *
|
|
+ * Author: Satoru Kawase
|
|
+ * Modified by: Xiao Qingyong
|
|
+ * Update kernel v4.18+ by : Audiophonics
|
|
+ * Copyright 2018 Audiophonics
|
|
+ *
|
|
+ * This program is free software; you can redistribute it and/or
|
|
+ * modify it under the terms of the GNU General Public License
|
|
+ * version 2 as published by the Free Software Foundation.
|
|
+ *
|
|
+ * This program is distributed in the hope that it will be useful, but
|
|
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
+ * General Public License for more details.
|
|
+ */
|
|
+
|
|
+#include <linux/kernel.h>
|
|
+#include <linux/init.h>
|
|
+#include <linux/module.h>
|
|
+#include <linux/delay.h>
|
|
+#include <linux/fs.h>
|
|
+#include <asm/uaccess.h>
|
|
+#include <sound/core.h>
|
|
+#include <sound/soc.h>
|
|
+#include <sound/pcm.h>
|
|
+#include <sound/pcm_params.h>
|
|
+
|
|
+#include "../codecs/i-sabre-codec.h"
|
|
+
|
|
+
|
|
+static int snd_rpi_i_sabre_q2m_init(struct snd_soc_pcm_runtime *rtd)
|
|
+{
|
|
+ struct snd_soc_component *component = rtd->codec_dai->component;
|
|
+ unsigned int value;
|
|
+
|
|
+ /* Device ID */
|
|
+ value = snd_soc_component_read32(component, ISABRECODEC_REG_01);
|
|
+ dev_info(component->card->dev, "Audiophonics Device ID : %02X\n", value);
|
|
+
|
|
+ /* API revision */
|
|
+ value = snd_soc_component_read32(component, ISABRECODEC_REG_02);
|
|
+ dev_info(component->card->dev, "Audiophonics API revision : %02X\n", value);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int snd_rpi_i_sabre_q2m_hw_params(
|
|
+ struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
|
|
+{
|
|
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
|
+ struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
|
|
+ int bclk_ratio;
|
|
+
|
|
+ bclk_ratio = snd_pcm_format_physical_width(
|
|
+ params_format(params)) * params_channels(params);
|
|
+ return snd_soc_dai_set_bclk_ratio(cpu_dai, bclk_ratio);
|
|
+}
|
|
+
|
|
+/* machine stream operations */
|
|
+static struct snd_soc_ops snd_rpi_i_sabre_q2m_ops = {
|
|
+ .hw_params = snd_rpi_i_sabre_q2m_hw_params,
|
|
+};
|
|
+
|
|
+
|
|
+static struct snd_soc_dai_link snd_rpi_i_sabre_q2m_dai[] = {
|
|
+ {
|
|
+ .name = "I-Sabre Q2M",
|
|
+ .stream_name = "I-Sabre Q2M DAC",
|
|
+ .cpu_dai_name = "bcm2708-i2s.0",
|
|
+ .codec_dai_name = "i-sabre-codec-dai",
|
|
+ .platform_name = "bcm2708-i2s.0",
|
|
+ .codec_name = "i-sabre-codec-i2c.1-0048",
|
|
+ .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
|
|
+ | SND_SOC_DAIFMT_CBS_CFS,
|
|
+ .init = snd_rpi_i_sabre_q2m_init,
|
|
+ .ops = &snd_rpi_i_sabre_q2m_ops,
|
|
+ }
|
|
+};
|
|
+
|
|
+/* audio machine driver */
|
|
+static struct snd_soc_card snd_rpi_i_sabre_q2m = {
|
|
+ .name = "I-Sabre Q2M DAC",
|
|
+ .owner = THIS_MODULE,
|
|
+ .dai_link = snd_rpi_i_sabre_q2m_dai,
|
|
+ .num_links = ARRAY_SIZE(snd_rpi_i_sabre_q2m_dai)
|
|
+};
|
|
+
|
|
+
|
|
+static int snd_rpi_i_sabre_q2m_probe(struct platform_device *pdev)
|
|
+{
|
|
+ int ret = 0;
|
|
+
|
|
+ snd_rpi_i_sabre_q2m.dev = &pdev->dev;
|
|
+ if (pdev->dev.of_node) {
|
|
+ struct device_node *i2s_node;
|
|
+ struct snd_soc_dai_link *dai;
|
|
+
|
|
+ dai = &snd_rpi_i_sabre_q2m_dai[0];
|
|
+ i2s_node = of_parse_phandle(pdev->dev.of_node,
|
|
+ "i2s-controller", 0);
|
|
+ if (i2s_node) {
|
|
+ dai->cpu_dai_name = NULL;
|
|
+ dai->cpu_of_node = i2s_node;
|
|
+ dai->platform_name = NULL;
|
|
+ dai->platform_of_node = i2s_node;
|
|
+ } else {
|
|
+ dev_err(&pdev->dev,
|
|
+ "Property 'i2s-controller' missing or invalid\n");
|
|
+ return (-EINVAL);
|
|
+ }
|
|
+
|
|
+ dai->name = "I-Sabre Q2M";
|
|
+ dai->stream_name = "I-Sabre Q2M DAC";
|
|
+ dai->dai_fmt = SND_SOC_DAIFMT_I2S
|
|
+ | SND_SOC_DAIFMT_NB_NF
|
|
+ | SND_SOC_DAIFMT_CBS_CFS;
|
|
+ }
|
|
+
|
|
+ /* Wait for registering codec driver */
|
|
+ mdelay(50);
|
|
+
|
|
+ ret = snd_soc_register_card(&snd_rpi_i_sabre_q2m);
|
|
+ if (ret) {
|
|
+ dev_err(&pdev->dev,
|
|
+ "snd_soc_register_card() failed: %d\n", ret);
|
|
+ }
|
|
+
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+static int snd_rpi_i_sabre_q2m_remove(struct platform_device *pdev)
|
|
+{
|
|
+ return snd_soc_unregister_card(&snd_rpi_i_sabre_q2m);
|
|
+}
|
|
+
|
|
+static const struct of_device_id snd_rpi_i_sabre_q2m_of_match[] = {
|
|
+ { .compatible = "audiophonics,i-sabre-q2m", },
|
|
+ {}
|
|
+};
|
|
+MODULE_DEVICE_TABLE(of, snd_rpi_i_sabre_q2m_of_match);
|
|
+
|
|
+static struct platform_driver snd_rpi_i_sabre_q2m_driver = {
|
|
+ .driver = {
|
|
+ .name = "snd-rpi-i-sabre-q2m",
|
|
+ .owner = THIS_MODULE,
|
|
+ .of_match_table = snd_rpi_i_sabre_q2m_of_match,
|
|
+ },
|
|
+ .probe = snd_rpi_i_sabre_q2m_probe,
|
|
+ .remove = snd_rpi_i_sabre_q2m_remove,
|
|
+};
|
|
+module_platform_driver(snd_rpi_i_sabre_q2m_driver);
|
|
+
|
|
+MODULE_DESCRIPTION("ASoC Driver for I-Sabre Q2M");
|
|
+MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
|
|
+MODULE_LICENSE("GPL");
|
|
--- a/sound/soc/codecs/Kconfig
|
|
+++ b/sound/soc/codecs/Kconfig
|
|
@@ -85,6 +85,7 @@ config SND_SOC_ALL_CODECS
|
|
select SND_SOC_ICS43432
|
|
select SND_SOC_INNO_RK3036
|
|
select SND_SOC_ISABELLE if I2C
|
|
+ select SND_SOC_I_SABRE_CODEC if I2C
|
|
select SND_SOC_JZ4740_CODEC
|
|
select SND_SOC_LM4857 if I2C
|
|
select SND_SOC_LM49453 if I2C
|
|
@@ -1322,4 +1323,8 @@ config SND_SOC_TPA6130A2
|
|
tristate "Texas Instruments TPA6130A2 headphone amplifier"
|
|
depends on I2C
|
|
|
|
+config SND_SOC_I_SABRE_CODEC
|
|
+ tristate "Audiophonics I-SABRE Codec"
|
|
+ depends on I2C
|
|
+
|
|
endmenu
|
|
--- a/sound/soc/codecs/Makefile
|
|
+++ b/sound/soc/codecs/Makefile
|
|
@@ -81,6 +81,7 @@ snd-soc-hdac-hdmi-objs := hdac_hdmi.o
|
|
snd-soc-ics43432-objs := ics43432.o
|
|
snd-soc-inno-rk3036-objs := inno_rk3036.o
|
|
snd-soc-isabelle-objs := isabelle.o
|
|
+snd-soc-i-sabre-codec-objs := i-sabre-codec.o
|
|
snd-soc-jz4740-codec-objs := jz4740.o
|
|
snd-soc-l3-objs := l3.o
|
|
snd-soc-lm4857-objs := lm4857.o
|
|
@@ -343,6 +344,7 @@ obj-$(CONFIG_SND_SOC_HDAC_HDMI) += snd-s
|
|
obj-$(CONFIG_SND_SOC_ICS43432) += snd-soc-ics43432.o
|
|
obj-$(CONFIG_SND_SOC_INNO_RK3036) += snd-soc-inno-rk3036.o
|
|
obj-$(CONFIG_SND_SOC_ISABELLE) += snd-soc-isabelle.o
|
|
+obj-$(CONFIG_SND_SOC_I_SABRE_CODEC) += snd-soc-i-sabre-codec.o
|
|
obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o
|
|
obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
|
|
obj-$(CONFIG_SND_SOC_LM4857) += snd-soc-lm4857.o
|
|
--- /dev/null
|
|
+++ b/sound/soc/codecs/i-sabre-codec.c
|
|
@@ -0,0 +1,392 @@
|
|
+/*
|
|
+ * Driver for I-Sabre Q2M
|
|
+ *
|
|
+ * Author: Satoru Kawase
|
|
+ * Modified by: Xiao Qingyong
|
|
+ * Modified by: JC BARBAUD (Mute)
|
|
+ * Update kernel v4.18+ by : Audiophonics
|
|
+ * Copyright 2018 Audiophonics
|
|
+ *
|
|
+ * This program is free software; you can redistribute it and/or
|
|
+ * modify it under the terms of the GNU General Public License
|
|
+ * version 2 as published by the Free Software Foundation.
|
|
+ *
|
|
+ * This program is distributed in the hope that it will be useful, but
|
|
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
+ * General Public License for more details.
|
|
+ */
|
|
+
|
|
+
|
|
+#include <linux/init.h>
|
|
+#include <linux/module.h>
|
|
+#include <linux/regmap.h>
|
|
+#include <linux/i2c.h>
|
|
+#include <sound/soc.h>
|
|
+#include <sound/pcm_params.h>
|
|
+#include <sound/tlv.h>
|
|
+
|
|
+#include "i-sabre-codec.h"
|
|
+
|
|
+
|
|
+/* I-Sabre Q2M Codec Private Data */
|
|
+struct i_sabre_codec_priv {
|
|
+ struct regmap *regmap;
|
|
+ unsigned int fmt;
|
|
+};
|
|
+
|
|
+
|
|
+/* I-Sabre Q2M Codec Default Register Value */
|
|
+static const struct reg_default i_sabre_codec_reg_defaults[] = {
|
|
+ { ISABRECODEC_REG_10, 0x00 },
|
|
+ { ISABRECODEC_REG_20, 0x00 },
|
|
+ { ISABRECODEC_REG_21, 0x00 },
|
|
+ { ISABRECODEC_REG_22, 0x00 },
|
|
+ { ISABRECODEC_REG_24, 0x00 },
|
|
+};
|
|
+
|
|
+
|
|
+static bool i_sabre_codec_writeable(struct device *dev, unsigned int reg)
|
|
+{
|
|
+ switch (reg) {
|
|
+ case ISABRECODEC_REG_10:
|
|
+ case ISABRECODEC_REG_20:
|
|
+ case ISABRECODEC_REG_21:
|
|
+ case ISABRECODEC_REG_22:
|
|
+ case ISABRECODEC_REG_24:
|
|
+ return true;
|
|
+
|
|
+ default:
|
|
+ return false;
|
|
+ }
|
|
+}
|
|
+
|
|
+static bool i_sabre_codec_readable(struct device *dev, unsigned int reg)
|
|
+{
|
|
+ switch (reg) {
|
|
+ case ISABRECODEC_REG_01:
|
|
+ case ISABRECODEC_REG_02:
|
|
+ case ISABRECODEC_REG_10:
|
|
+ case ISABRECODEC_REG_20:
|
|
+ case ISABRECODEC_REG_21:
|
|
+ case ISABRECODEC_REG_22:
|
|
+ case ISABRECODEC_REG_24:
|
|
+ return true;
|
|
+
|
|
+ default:
|
|
+ return false;
|
|
+ }
|
|
+}
|
|
+
|
|
+static bool i_sabre_codec_volatile(struct device *dev, unsigned int reg)
|
|
+{
|
|
+ switch (reg) {
|
|
+ case ISABRECODEC_REG_01:
|
|
+ case ISABRECODEC_REG_02:
|
|
+ return true;
|
|
+
|
|
+ default:
|
|
+ return false;
|
|
+ }
|
|
+}
|
|
+
|
|
+
|
|
+/* Volume Scale */
|
|
+static const DECLARE_TLV_DB_SCALE(volume_tlv, -10000, 100, 0);
|
|
+
|
|
+
|
|
+/* Filter Type */
|
|
+static const char * const fir_filter_type_texts[] = {
|
|
+ "brick wall",
|
|
+ "corrected minimum phase fast",
|
|
+ "minimum phase slow",
|
|
+ "minimum phase fast",
|
|
+ "linear phase slow",
|
|
+ "linear phase fast",
|
|
+ "apodizing fast",
|
|
+};
|
|
+
|
|
+static SOC_ENUM_SINGLE_DECL(i_sabre_fir_filter_type_enum,
|
|
+ ISABRECODEC_REG_22, 0, fir_filter_type_texts);
|
|
+
|
|
+
|
|
+/* I2S / SPDIF Select */
|
|
+static const char * const iis_spdif_sel_texts[] = {
|
|
+ "I2S",
|
|
+ "SPDIF",
|
|
+};
|
|
+
|
|
+static SOC_ENUM_SINGLE_DECL(i_sabre_iis_spdif_sel_enum,
|
|
+ ISABRECODEC_REG_24, 0, iis_spdif_sel_texts);
|
|
+
|
|
+
|
|
+/* Control */
|
|
+static const struct snd_kcontrol_new i_sabre_codec_controls[] = {
|
|
+SOC_SINGLE_RANGE_TLV("Digital Playback Volume", ISABRECODEC_REG_20, 0, 0, 100, 1, volume_tlv),
|
|
+SOC_SINGLE("Digital Playback Switch", ISABRECODEC_REG_21, 0, 1, 1),
|
|
+SOC_ENUM("FIR Filter Type", i_sabre_fir_filter_type_enum),
|
|
+SOC_ENUM("I2S/SPDIF Select", i_sabre_iis_spdif_sel_enum),
|
|
+};
|
|
+
|
|
+
|
|
+static const u32 i_sabre_codec_dai_rates_slave[] = {
|
|
+ 8000, 11025, 16000, 22050, 32000,
|
|
+ 44100, 48000, 64000, 88200, 96000,
|
|
+ 176400, 192000, 352800, 384000,
|
|
+ 705600, 768000, 1411200, 1536000
|
|
+};
|
|
+
|
|
+static const struct snd_pcm_hw_constraint_list constraints_slave = {
|
|
+ .list = i_sabre_codec_dai_rates_slave,
|
|
+ .count = ARRAY_SIZE(i_sabre_codec_dai_rates_slave),
|
|
+};
|
|
+
|
|
+static int i_sabre_codec_dai_startup_slave(
|
|
+ struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
|
|
+{
|
|
+ struct snd_soc_component *component = dai->component;
|
|
+ int ret;
|
|
+
|
|
+ ret = snd_pcm_hw_constraint_list(substream->runtime,
|
|
+ 0, SNDRV_PCM_HW_PARAM_RATE, &constraints_slave);
|
|
+ if (ret != 0) {
|
|
+ dev_err(component->card->dev, "Failed to setup rates constraints: %d\n", ret);
|
|
+ }
|
|
+
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+static int i_sabre_codec_dai_startup(
|
|
+ struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
|
|
+{
|
|
+ struct snd_soc_component *component = dai->component;
|
|
+ struct i_sabre_codec_priv *i_sabre_codec
|
|
+ = snd_soc_component_get_drvdata(component);
|
|
+
|
|
+ switch (i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
+ case SND_SOC_DAIFMT_CBS_CFS:
|
|
+ return i_sabre_codec_dai_startup_slave(substream, dai);
|
|
+
|
|
+ default:
|
|
+ return (-EINVAL);
|
|
+ }
|
|
+}
|
|
+
|
|
+static int i_sabre_codec_hw_params(
|
|
+ struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params,
|
|
+ struct snd_soc_dai *dai)
|
|
+{
|
|
+ struct snd_soc_component *component = dai->component;
|
|
+ struct i_sabre_codec_priv *i_sabre_codec
|
|
+ = snd_soc_component_get_drvdata(component);
|
|
+ unsigned int daifmt;
|
|
+ int format_width;
|
|
+
|
|
+ dev_dbg(component->card->dev, "hw_params %u Hz, %u channels\n",
|
|
+ params_rate(params), params_channels(params));
|
|
+
|
|
+ /* Check I2S Format (Bit Size) */
|
|
+ format_width = snd_pcm_format_width(params_format(params));
|
|
+ if ((format_width != 32) && (format_width != 16)) {
|
|
+ dev_err(component->card->dev, "Bad frame size: %d\n",
|
|
+ snd_pcm_format_width(params_format(params)));
|
|
+ return (-EINVAL);
|
|
+ }
|
|
+
|
|
+ /* Check Slave Mode */
|
|
+ daifmt = i_sabre_codec->fmt & SND_SOC_DAIFMT_MASTER_MASK;
|
|
+ if (daifmt != SND_SOC_DAIFMT_CBS_CFS) {
|
|
+ return (-EINVAL);
|
|
+ }
|
|
+
|
|
+ /* Notify Sampling Frequency */
|
|
+ switch (params_rate(params))
|
|
+ {
|
|
+ case 44100:
|
|
+ case 48000:
|
|
+ case 88200:
|
|
+ case 96000:
|
|
+ case 176400:
|
|
+ case 192000:
|
|
+ snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x00);
|
|
+ break;
|
|
+
|
|
+ case 352800:
|
|
+ case 384000:
|
|
+ case 705600:
|
|
+ case 768000:
|
|
+ case 1411200:
|
|
+ case 1536000:
|
|
+ snd_soc_component_update_bits(component, ISABRECODEC_REG_10, 0x01, 0x01);
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int i_sabre_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
|
|
+{
|
|
+ struct snd_soc_component *component = dai->component;
|
|
+ struct i_sabre_codec_priv *i_sabre_codec
|
|
+ = snd_soc_component_get_drvdata(component);
|
|
+
|
|
+ /* interface format */
|
|
+ switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
+ case SND_SOC_DAIFMT_I2S:
|
|
+ break;
|
|
+
|
|
+ case SND_SOC_DAIFMT_RIGHT_J:
|
|
+ case SND_SOC_DAIFMT_LEFT_J:
|
|
+ default:
|
|
+ return (-EINVAL);
|
|
+ }
|
|
+
|
|
+ /* clock inversion */
|
|
+ if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF) {
|
|
+ return (-EINVAL);
|
|
+ }
|
|
+
|
|
+ /* Set Audio Data Format */
|
|
+ i_sabre_codec->fmt = fmt;
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int i_sabre_codec_dac_mute(struct snd_soc_dai *dai, int mute)
|
|
+{
|
|
+ struct snd_soc_component *component = dai->component;
|
|
+
|
|
+ if (mute) {
|
|
+ snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x01);
|
|
+ } else {
|
|
+ snd_soc_component_update_bits(component, ISABRECODEC_REG_21, 0x01, 0x00);
|
|
+ }
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+
|
|
+static const struct snd_soc_dai_ops i_sabre_codec_dai_ops = {
|
|
+ .startup = i_sabre_codec_dai_startup,
|
|
+ .hw_params = i_sabre_codec_hw_params,
|
|
+ .set_fmt = i_sabre_codec_set_fmt,
|
|
+ .digital_mute = i_sabre_codec_dac_mute,
|
|
+};
|
|
+
|
|
+static struct snd_soc_dai_driver i_sabre_codec_dai = {
|
|
+ .name = "i-sabre-codec-dai",
|
|
+ .playback = {
|
|
+ .stream_name = "Playback",
|
|
+ .channels_min = 2,
|
|
+ .channels_max = 2,
|
|
+ .rates = SNDRV_PCM_RATE_CONTINUOUS,
|
|
+ .rate_min = 8000,
|
|
+ .rate_max = 1536000,
|
|
+ .formats = SNDRV_PCM_FMTBIT_S16_LE
|
|
+ | SNDRV_PCM_FMTBIT_S32_LE,
|
|
+ },
|
|
+ .ops = &i_sabre_codec_dai_ops,
|
|
+};
|
|
+
|
|
+static struct snd_soc_component_driver i_sabre_codec_codec_driver = {
|
|
+ .controls = i_sabre_codec_controls,
|
|
+ .num_controls = ARRAY_SIZE(i_sabre_codec_controls),
|
|
+};
|
|
+
|
|
+
|
|
+static const struct regmap_config i_sabre_codec_regmap = {
|
|
+ .reg_bits = 8,
|
|
+ .val_bits = 8,
|
|
+ .max_register = ISABRECODEC_MAX_REG,
|
|
+
|
|
+ .reg_defaults = i_sabre_codec_reg_defaults,
|
|
+ .num_reg_defaults = ARRAY_SIZE(i_sabre_codec_reg_defaults),
|
|
+
|
|
+ .writeable_reg = i_sabre_codec_writeable,
|
|
+ .readable_reg = i_sabre_codec_readable,
|
|
+ .volatile_reg = i_sabre_codec_volatile,
|
|
+
|
|
+ .cache_type = REGCACHE_RBTREE,
|
|
+};
|
|
+
|
|
+
|
|
+static int i_sabre_codec_probe(struct device *dev, struct regmap *regmap)
|
|
+{
|
|
+ struct i_sabre_codec_priv *i_sabre_codec;
|
|
+ int ret;
|
|
+
|
|
+ i_sabre_codec = devm_kzalloc(dev, sizeof(*i_sabre_codec), GFP_KERNEL);
|
|
+ if (!i_sabre_codec) {
|
|
+ dev_err(dev, "devm_kzalloc");
|
|
+ return (-ENOMEM);
|
|
+ }
|
|
+
|
|
+ i_sabre_codec->regmap = regmap;
|
|
+
|
|
+ dev_set_drvdata(dev, i_sabre_codec);
|
|
+
|
|
+ ret = snd_soc_register_component(dev,
|
|
+ &i_sabre_codec_codec_driver, &i_sabre_codec_dai, 1);
|
|
+ if (ret != 0) {
|
|
+ dev_err(dev, "Failed to register CODEC: %d\n", ret);
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static void i_sabre_codec_remove(struct device *dev)
|
|
+{
|
|
+ snd_soc_unregister_component(dev);
|
|
+}
|
|
+
|
|
+
|
|
+static int i_sabre_codec_i2c_probe(
|
|
+ struct i2c_client *i2c, const struct i2c_device_id *id)
|
|
+{
|
|
+ struct regmap *regmap;
|
|
+
|
|
+ regmap = devm_regmap_init_i2c(i2c, &i_sabre_codec_regmap);
|
|
+ if (IS_ERR(regmap)) {
|
|
+ return PTR_ERR(regmap);
|
|
+ }
|
|
+
|
|
+ return i_sabre_codec_probe(&i2c->dev, regmap);
|
|
+}
|
|
+
|
|
+static int i_sabre_codec_i2c_remove(struct i2c_client *i2c)
|
|
+{
|
|
+ i_sabre_codec_remove(&i2c->dev);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+
|
|
+static const struct i2c_device_id i_sabre_codec_i2c_id[] = {
|
|
+ { "i-sabre-codec", },
|
|
+ { }
|
|
+};
|
|
+MODULE_DEVICE_TABLE(i2c, i_sabre_codec_i2c_id);
|
|
+
|
|
+static const struct of_device_id i_sabre_codec_of_match[] = {
|
|
+ { .compatible = "audiophonics,i-sabre-codec", },
|
|
+ { }
|
|
+};
|
|
+MODULE_DEVICE_TABLE(of, i_sabre_codec_of_match);
|
|
+
|
|
+static struct i2c_driver i_sabre_codec_i2c_driver = {
|
|
+ .driver = {
|
|
+ .name = "i-sabre-codec-i2c",
|
|
+ .owner = THIS_MODULE,
|
|
+ .of_match_table = of_match_ptr(i_sabre_codec_of_match),
|
|
+ },
|
|
+ .probe = i_sabre_codec_i2c_probe,
|
|
+ .remove = i_sabre_codec_i2c_remove,
|
|
+ .id_table = i_sabre_codec_i2c_id,
|
|
+};
|
|
+module_i2c_driver(i_sabre_codec_i2c_driver);
|
|
+
|
|
+
|
|
+MODULE_DESCRIPTION("ASoC I-Sabre Q2M codec driver");
|
|
+MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
|
|
+MODULE_LICENSE("GPL");
|
|
--- /dev/null
|
|
+++ b/sound/soc/codecs/i-sabre-codec.h
|
|
@@ -0,0 +1,42 @@
|
|
+/*
|
|
+ * Driver for I-Sabre Q2M
|
|
+ *
|
|
+ * Author: Satoru Kawase
|
|
+ * Modified by: Xiao Qingyong
|
|
+ * Copyright 2018 Audiophonics
|
|
+ *
|
|
+ * This program is free software; you can redistribute it and/or
|
|
+ * modify it under the terms of the GNU General Public License
|
|
+ * version 2 as published by the Free Software Foundation.
|
|
+ *
|
|
+ * This program is distributed in the hope that it will be useful, but
|
|
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
+ * General Public License for more details.
|
|
+ */
|
|
+
|
|
+#ifndef _SND_SOC_ISABRECODEC
|
|
+#define _SND_SOC_ISABRECODEC
|
|
+
|
|
+
|
|
+/* ISABRECODEC Register Address */
|
|
+#define ISABRECODEC_REG_01 0x01 /* Virtual Device ID : 0x01 = es9038q2m */
|
|
+#define ISABRECODEC_REG_02 0x02 /* API revision : 0x01 = Revision 01 */
|
|
+#define ISABRECODEC_REG_10 0x10 /* 0x01 = above 192kHz, 0x00 = otherwise */
|
|
+#define ISABRECODEC_REG_20 0x20 /* 0 - 100 (decimal value, 0 = min., 100 = max.) */
|
|
+#define ISABRECODEC_REG_21 0x21 /* 0x00 = Mute OFF, 0x01 = Mute ON */
|
|
+#define ISABRECODEC_REG_22 0x22
|
|
+/*
|
|
+ 0x00 = brick wall,
|
|
+ 0x01 = corrected minimum phase fast,
|
|
+ 0x02 = minimum phase slow,
|
|
+ 0x03 = minimum phase fast,
|
|
+ 0x04 = linear phase slow,
|
|
+ 0x05 = linear phase fast,
|
|
+ 0x06 = apodizing fast,
|
|
+*/
|
|
+//#define ISABRECODEC_REG_23 0x23 /* reserved */
|
|
+#define ISABRECODEC_REG_24 0x24 /* 0x00 = I2S, 0x01 = SPDIF */
|
|
+#define ISABRECODEC_MAX_REG 0x24 /* Maximum Register Number */
|
|
+
|
|
+#endif /* _SND_SOC_ISABRECODEC */
|