diff --git a/arch/arm/boot/dts/overlays/Makefile b/arch/arm/boot/dts/overlays/Makefile
index bb350f667f0a2a..6ab8969f9d85f7 100644
--- a/arch/arm/boot/dts/overlays/Makefile
+++ b/arch/arm/boot/dts/overlays/Makefile
@@ -31,7 +31,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
audremap.dtbo \
balena-fin.dtbo \
cap1106.dtbo \
- chipdip-i2s-master-dac.dtbo \
+ chipdip-dac.dtbo \
cma.dtbo \
dht11.dtbo \
dionaudio-loco.dtbo \
diff --git a/arch/arm/boot/dts/overlays/README b/arch/arm/boot/dts/overlays/README
index a2c7631cc6d780..feb605b6cd0118 100644
--- a/arch/arm/boot/dts/overlays/README
+++ b/arch/arm/boot/dts/overlays/README
@@ -628,9 +628,9 @@ Load: dtoverlay=cap1106,=
Params: int_pin GPIO pin for interrupt signal (default 23)
-Name: chipdip-i2s-master-dac
-Info: Configures Raspberry PI to work as I2S slave with BCLK=64Fs.
-Load: dtoverlay=chipdip-i2s-master-dac
+Name: chipdip-dac
+Info: Configures Chip Dip audio cards.
+Load: dtoverlay=chipdip-dac
Params:
diff --git a/arch/arm/boot/dts/overlays/chipdip-dac-overlay.dts b/arch/arm/boot/dts/overlays/chipdip-dac-overlay.dts
new file mode 100644
index 00000000000000..09c7417b470768
--- /dev/null
+++ b/arch/arm/boot/dts/overlays/chipdip-dac-overlay.dts
@@ -0,0 +1,46 @@
+/*
+ * Device Tree overlay for ChipDip DAC
+ */
+
+/dts-v1/;
+/plugin/;
+
+/ {
+ compatible = "brcm,bcm2835";
+
+ fragment@0 {
+ target = <&i2s>;
+ __overlay__ {
+ status = "okay";
+ };
+ };
+
+ fragment@1 {
+ target-path = "/";
+ __overlay__ {
+ spdif-transmitter {
+ #address-cells = <0>;
+ #size-cells = <0>;
+ #sound-dai-cells = <0>;
+ compatible = "linux,spdif-dit";
+ status = "okay";
+ };
+ };
+ };
+
+ fragment@2 {
+ target = <&sound>;
+ __overlay__ {
+ compatible = "chipdip,chipdip-dac";
+ i2s-controller = <&i2s>;
+ sr0-gpios = <&gpio 5 0>;
+ sr1-gpios = <&gpio 6 0>;
+ sr2-gpios = <&gpio 12 0>;
+ res0-gpios = <&gpio 24 0>;
+ res1-gpios = <&gpio 27 0>;
+ mute-gpios = <&gpio 4 0>;
+ sdwn-gpios = <&gpio 13 0>;
+ status = "okay";
+ };
+ };
+};
diff --git a/arch/arm/boot/dts/overlays/chipdip-i2s-master-dac-overlay.dts b/arch/arm/boot/dts/overlays/chipdip-i2s-master-dac-overlay.dts
deleted file mode 100644
index a35ac36f85134f..00000000000000
--- a/arch/arm/boot/dts/overlays/chipdip-i2s-master-dac-overlay.dts
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Device Tree overlay for ChipDip I2S master DAC
- */
-
-/dts-v1/;
-/plugin/;
-
-/ {
- compatible = "brcm,bcm2835";
- fragment@0 {
- target = <&sound>;
- __overlay__ {
- compatible = "simple-audio-card";
- simple-audio-card,name = "ChipDip I2S master DAC";
- status="okay";
- playback_link: simple-audio-card,dai-link@0 {
- format = "i2s";
- bitclock-master = <&p_codec_dai>;
- frame-master = <&p_codec_dai>;
- p_cpu_dai: cpu {
- sound-dai = <&i2s>;
- dai-tdm-slot-num = <2>;
- dai-tdm-slot-width = <32>;
- };
-
- p_codec_dai: codec {
- sound-dai = <&codec_out>;
- };
- };
- };
- };
-
- fragment@1 {
- target-path = "/";
- __overlay__ {
- codec_out: spdif-transmitter {
- #address-cells = <0>;
- #size-cells = <0>;
- #sound-dai-cells = <0>;
- compatible = "linux,spdif-dit";
- status = "okay";
- };
- };
- };
-
- fragment@2 {
- target = <&i2s>;
- __overlay__ {
- #sound-dai-cells = <0>;
- status = "okay";
- };
- };
-};
diff --git a/arch/arm/configs/bcm2709_defconfig b/arch/arm/configs/bcm2709_defconfig
index 639d69949862c2..55d68bdfde0b43 100644
--- a/arch/arm/configs/bcm2709_defconfig
+++ b/arch/arm/configs/bcm2709_defconfig
@@ -979,6 +979,7 @@ CONFIG_SND_USB_6FIRE=m
CONFIG_SND_USB_HIFACE=m
CONFIG_SND_SOC=m
CONFIG_SND_BCM2835_SOC_I2S=m
+CONFIG_SND_BCM2708_SOC_CHIPDIP_DAC=m
CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD=m
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
diff --git a/arch/arm/configs/bcm2711_defconfig b/arch/arm/configs/bcm2711_defconfig
index 068b2c8689be63..64f1206f0bd590 100644
--- a/arch/arm/configs/bcm2711_defconfig
+++ b/arch/arm/configs/bcm2711_defconfig
@@ -994,6 +994,7 @@ CONFIG_SND_USB_6FIRE=m
CONFIG_SND_USB_HIFACE=m
CONFIG_SND_SOC=m
CONFIG_SND_BCM2835_SOC_I2S=m
+CONFIG_SND_BCM2708_SOC_CHIPDIP_DAC=m
CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD=m
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
diff --git a/arch/arm/configs/bcmrpi_defconfig b/arch/arm/configs/bcmrpi_defconfig
index 7e5dcab65cdb6d..b939d3ba58b574 100644
--- a/arch/arm/configs/bcmrpi_defconfig
+++ b/arch/arm/configs/bcmrpi_defconfig
@@ -972,6 +972,7 @@ CONFIG_SND_USB_6FIRE=m
CONFIG_SND_USB_HIFACE=m
CONFIG_SND_SOC=m
CONFIG_SND_BCM2835_SOC_I2S=m
+CONFIG_SND_BCM2708_SOC_CHIPDIP_DAC=m
CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD=m
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
diff --git a/arch/arm64/configs/bcm2711_defconfig b/arch/arm64/configs/bcm2711_defconfig
index 1771618bfe9e2d..01297528be0d6e 100644
--- a/arch/arm64/configs/bcm2711_defconfig
+++ b/arch/arm64/configs/bcm2711_defconfig
@@ -995,6 +995,7 @@ CONFIG_SND_USB_6FIRE=m
CONFIG_SND_USB_HIFACE=m
CONFIG_SND_SOC=m
CONFIG_SND_BCM2835_SOC_I2S=m
+CONFIG_SND_BCM2708_SOC_CHIPDIP_DAC=m
CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD=m
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
diff --git a/arch/arm64/configs/bcmrpi3_defconfig b/arch/arm64/configs/bcmrpi3_defconfig
index 13aa02396b7b63..178848f3c993a4 100644
--- a/arch/arm64/configs/bcmrpi3_defconfig
+++ b/arch/arm64/configs/bcmrpi3_defconfig
@@ -907,6 +907,7 @@ CONFIG_SND_USB_CAIAQ_INPUT=y
CONFIG_SND_USB_6FIRE=m
CONFIG_SND_SOC=m
CONFIG_SND_BCM2835_SOC_I2S=m
+CONFIG_SND_BCM2708_SOC_CHIPDIP_DAC=m
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSHD=m
diff --git a/sound/soc/bcm/Kconfig b/sound/soc/bcm/Kconfig
index 94c2a8e8ad2d53..d65df373c39eb1 100644
--- a/sound/soc/bcm/Kconfig
+++ b/sound/soc/bcm/Kconfig
@@ -27,6 +27,12 @@ config SND_BCM63XX_I2S_WHISTLER
If you don't know what to do here, say N
+config SND_BCM2708_SOC_CHIPDIP_DAC
+ tristate "Support for the ChipDip DAC"
+ depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
+ help
+ Say Y or M if you want to add support for the ChipDip DAC soundcard
+
config SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD
tristate "Support for Google voiceHAT soundcard"
depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
diff --git a/sound/soc/bcm/Makefile b/sound/soc/bcm/Makefile
index 942464a729b37e..1efb734f1c864c 100644
--- a/sound/soc/bcm/Makefile
+++ b/sound/soc/bcm/Makefile
@@ -47,6 +47,7 @@ snd-soc-fe-pi-audio-objs := fe-pi-audio.o
snd-soc-rpi-simple-soundcard-objs := rpi-simple-soundcard.o
snd-soc-rpi-wm8804-soundcard-objs := rpi-wm8804-soundcard.o
snd-soc-pifi-40-objs := pifi-40.o
+snd-soc-chipdip-dac-objs := chipdip-dac.o
obj-$(CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD) += snd-soc-googlevoicehat-codec.o
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
@@ -78,4 +79,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO) += snd-soc-fe-pi-audio.o
obj-$(CONFIG_SND_RPI_SIMPLE_SOUNDCARD) += snd-soc-rpi-simple-soundcard.o
obj-$(CONFIG_SND_RPI_WM8804_SOUNDCARD) += snd-soc-rpi-wm8804-soundcard.o
obj-$(CONFIG_SND_BCM2708_SOC_PIFI_40) += snd-soc-pifi-40.o
-
+obj-$(CONFIG_SND_BCM2708_SOC_CHIPDIP_DAC) += snd-soc-chipdip-dac.o
diff --git a/sound/soc/bcm/chipdip-dac.c b/sound/soc/bcm/chipdip-dac.c
new file mode 100644
index 00000000000000..6cb53692b3c5ad
--- /dev/null
+++ b/sound/soc/bcm/chipdip-dac.c
@@ -0,0 +1,275 @@
+/*
+ * ASoC Driver for ChipDip DAC
+ *
+ * Author: Evgenij Sapunov
+ * Copyright 2021
+ * based on code by Milan Neskovic
+ * based on code by Jaikumar
+ *
+ * Thanks to Phil Elwell (pelwell) for help.
+ *
+ * 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
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+#define SR_BIT_0 0 //sample rate bits
+#define SR_BIT_1 1
+#define SR_BIT_2 2
+#define BD_BIT_0 3 //bit depth bits
+#define BD_BIT_1 4
+
+#define SAMPLE_RATE_MASK_44_1 0
+#define SAMPLE_RATE_MASK_48 (1 << SR_BIT_0)
+#define SAMPLE_RATE_MASK_88_2 ((1 << SR_BIT_2) | (1 << SR_BIT_1))
+#define SAMPLE_RATE_MASK_96 (1 << SR_BIT_1)
+#define SAMPLE_RATE_MASK_176_4 ((1 << SR_BIT_2) | (1 << SR_BIT_1) | (1 << SR_BIT_0))
+#define SAMPLE_RATE_MASK_192 ((1 << SR_BIT_1) | (1 << SR_BIT_0))
+#define SAMPLE_RATE_MASK ((1 << SR_BIT_2) | (1 << SR_BIT_1) | (1 << SR_BIT_0))
+
+#define BIT_DEPTH_MASK_16 0
+#define BIT_DEPTH_MASK_24 (1 << BD_BIT_0)
+#define BIT_DEPTH_MASK_32 (1 << BD_BIT_1)
+#define BIT_DEPTH_MASK ((1 << BD_BIT_1) | (1 << BD_BIT_0))
+
+#define MUTE_ACTIVE 0
+#define MUTE_NOT_ACTIVE 1
+
+#define HW_PARAMS_GPIO_COUNT 5
+
+static struct gpio_desc *mute_gpio;
+static struct gpio_desc *sdwn_gpio;
+static struct gpio_desc *hw_params_gpios[HW_PARAMS_GPIO_COUNT];
+static int current_width;
+static int current_rate;
+
+static void snd_rpi_chipdip_dac_gpio_array_set(int value);
+static void snd_rpi_chipdip_dac_gpio_set(struct gpio_desc *gpio_item, int value);
+
+static void snd_rpi_chipdip_dac_gpio_array_set(int value)
+{
+ int i = 0;
+
+ for (i = 0; i < HW_PARAMS_GPIO_COUNT; i++)
+ snd_rpi_chipdip_dac_gpio_set(hw_params_gpios[i], ((value >> i) & 1));
+}
+
+static void snd_rpi_chipdip_dac_gpio_set(struct gpio_desc *gpio_item, int value)
+{
+ if (gpio_item)
+ gpiod_set_value_cansleep(gpio_item, value);
+}
+
+static int snd_rpi_chipdip_dac_init(struct snd_soc_pcm_runtime *rtd)
+{
+ return 0;
+}
+
+static int snd_rpi_chipdip_dac_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ int ret = 0;
+ int gpio_change_pending = 0;
+ int sample_rate_state = 0;
+ int bit_depth_state = 0;
+ int param_value = params_width(params);
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+
+ ret = snd_soc_dai_set_bclk_ratio(asoc_rtd_to_cpu(rtd, 0), 2 * 32);
+
+ if (current_width != param_value) {
+ current_width = param_value;
+ gpio_change_pending = 1;
+
+ switch (param_value) {
+ case 16:
+ bit_depth_state = BIT_DEPTH_MASK_16;
+ break;
+ case 24:
+ bit_depth_state = BIT_DEPTH_MASK_24;
+ break;
+ case 32:
+ bit_depth_state = BIT_DEPTH_MASK_32;
+ break;
+ default:
+ return -EINVAL;
+ }
+ }
+
+ param_value = params_rate(params);
+ if (current_rate != param_value) {
+ current_rate = param_value;
+ gpio_change_pending = 1;
+
+ switch (param_value) {
+ case 44100:
+ sample_rate_state = SAMPLE_RATE_MASK_44_1;
+ break;
+ case 48000:
+ sample_rate_state = SAMPLE_RATE_MASK_48;
+ break;
+ case 88200:
+ sample_rate_state = SAMPLE_RATE_MASK_88_2;
+ break;
+ case 96000:
+ sample_rate_state = SAMPLE_RATE_MASK_96;
+ break;
+ case 176400:
+ sample_rate_state = SAMPLE_RATE_MASK_176_4;
+ break;
+ case 192000:
+ sample_rate_state = SAMPLE_RATE_MASK_192;
+ break;
+ default:
+ return -EINVAL;
+ }
+ }
+
+ if (gpio_change_pending) {
+ snd_rpi_chipdip_dac_gpio_set(mute_gpio, MUTE_ACTIVE);
+ snd_rpi_chipdip_dac_gpio_array_set(bit_depth_state | sample_rate_state);
+ msleep(300);
+ snd_rpi_chipdip_dac_gpio_set(mute_gpio, MUTE_NOT_ACTIVE);
+ }
+
+ return ret;
+}
+
+static int snd_rpi_chipdip_dac_startup(struct snd_pcm_substream *substream)
+{
+ return 0;
+}
+
+static void snd_rpi_chipdip_dac_shutdown(struct snd_pcm_substream *substream)
+{
+
+}
+
+/* machine stream operations */
+static struct snd_soc_ops snd_rpi_chipdip_dac_ops = {
+ .hw_params = snd_rpi_chipdip_dac_hw_params,
+ .startup = snd_rpi_chipdip_dac_startup,
+ .shutdown = snd_rpi_chipdip_dac_shutdown,
+};
+
+SND_SOC_DAILINK_DEFS(hifi,
+ DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
+ DAILINK_COMP_ARRAY(COMP_CODEC("spdif-transmitter", "dit-hifi")),
+ DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
+
+static struct snd_soc_dai_link snd_rpi_chipdip_dac_dai[] = {
+{
+ .name = "ChipDip DAC",
+ .stream_name = "ChipDip DAC HiFi",
+ .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+ SND_SOC_DAIFMT_CBM_CFM,
+ .ops = &snd_rpi_chipdip_dac_ops,
+ .init = snd_rpi_chipdip_dac_init,
+ SND_SOC_DAILINK_REG(hifi),
+},
+};
+
+/* audio machine driver */
+static struct snd_soc_card snd_rpi_chipdip_dac = {
+ .name = "ChipDipDAC",
+ .driver_name = "ChipdipDac",
+ .owner = THIS_MODULE,
+ .dai_link = snd_rpi_chipdip_dac_dai,
+ .num_links = ARRAY_SIZE(snd_rpi_chipdip_dac_dai),
+};
+
+static int snd_rpi_chipdip_dac_probe(struct platform_device *pdev)
+{
+ int ret = 0;
+ int i = 0;
+
+ snd_rpi_chipdip_dac.dev = &pdev->dev;
+
+ if (pdev->dev.of_node) {
+ struct device_node *i2s_node;
+ struct snd_soc_dai_link *dai = &snd_rpi_chipdip_dac_dai[0];
+ i2s_node = of_parse_phandle(pdev->dev.of_node,
+ "i2s-controller", 0);
+
+ if (i2s_node) {
+ dai->cpus->dai_name = NULL;
+ dai->cpus->of_node = i2s_node;
+ dai->platforms->name = NULL;
+ dai->platforms->of_node = i2s_node;
+ }
+ }
+
+ hw_params_gpios[SR_BIT_0] = devm_gpiod_get_optional(&pdev->dev, "sr0", GPIOD_OUT_LOW);
+ hw_params_gpios[SR_BIT_1] = devm_gpiod_get_optional(&pdev->dev, "sr1", GPIOD_OUT_LOW);
+ hw_params_gpios[SR_BIT_2] = devm_gpiod_get_optional(&pdev->dev, "sr2", GPIOD_OUT_LOW);
+ hw_params_gpios[BD_BIT_0] = devm_gpiod_get_optional(&pdev->dev, "res0", GPIOD_OUT_LOW);
+ hw_params_gpios[BD_BIT_1] = devm_gpiod_get_optional(&pdev->dev, "res1", GPIOD_OUT_LOW);
+ mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute", GPIOD_OUT_LOW);
+ sdwn_gpio = devm_gpiod_get_optional(&pdev->dev, "sdwn", GPIOD_OUT_HIGH);
+
+ for (i = 0; i < HW_PARAMS_GPIO_COUNT; i++) {
+ if (IS_ERR(hw_params_gpios[i])) {
+ ret = PTR_ERR(hw_params_gpios[i]);
+ dev_err(&pdev->dev, "failed to get hw_params gpio: %d\n", ret);
+ return ret;
+ }
+ }
+
+ if (IS_ERR(mute_gpio)) {
+ ret = PTR_ERR(mute_gpio);
+ dev_err(&pdev->dev, "failed to get mute gpio: %d\n", ret);
+ return ret;
+ }
+
+ if (IS_ERR(sdwn_gpio)) {
+ ret = PTR_ERR(sdwn_gpio);
+ dev_err(&pdev->dev, "failed to get sdwn gpio: %d\n", ret);
+ return ret;
+ }
+
+ snd_rpi_chipdip_dac_gpio_set(sdwn_gpio, 1);
+
+ ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_chipdip_dac);
+ if (ret && ret != -EPROBE_DEFER)
+ dev_err(&pdev->dev,
+ "snd_soc_register_card() failed: %d\n", ret);
+
+ return ret;
+}
+
+static const struct of_device_id snd_rpi_chipdip_dac_of_match[] = {
+ { .compatible = "chipdip,chipdip-dac", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, snd_rpi_chipdip_dac_of_match);
+
+static struct platform_driver snd_rpi_chipdip_dac_driver = {
+ .driver = {
+ .name = "snd-rpi-chipdip-dac",
+ .owner = THIS_MODULE,
+ .of_match_table = snd_rpi_chipdip_dac_of_match,
+ },
+ .probe = snd_rpi_chipdip_dac_probe,
+};
+
+module_platform_driver(snd_rpi_chipdip_dac_driver);
+
+MODULE_AUTHOR("Evgenij Sapunov ");
+MODULE_DESCRIPTION("ASoC Driver for ChipDip DAC");
+MODULE_LICENSE("GPL v2");