Add ALSA based HDMI I2S audio driver for dw_hdmi. Sound card
driver could connect to this codec through the codec dai name
"dw-hdmi-i2s-audio".
Signed-off-by: Yakir Yang
---
drivers/gpu/drm/bridge/Kconfig | 9 +
drivers/gpu/drm/bridge/Makefile| 1 +
drivers/gpu/drm/bridge/dw_hdmi-i2s-audio.c | 412 +
drivers/gpu/drm/bridge/dw_hdmi.c | 24 +-
drivers/gpu/drm/bridge/dw_hdmi.h | 3 +
5 files changed, 440 insertions(+), 9 deletions(-)
create mode 100644 drivers/gpu/drm/bridge/dw_hdmi-i2s-audio.c
diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
index 9fff41e..fa8a9d2 100644
--- a/drivers/gpu/drm/bridge/Kconfig
+++ b/drivers/gpu/drm/bridge/Kconfig
@@ -14,6 +14,15 @@ config DRM_DW_HDMI_AHB_AUDIO
Designware HDMI block. This is used in conjunction with
the i.MX6 HDMI driver.
+config DRM_DW_HDMI_I2S_AUDIO
+ tristate "Synopsis Designware I2S Audio interface"
+ depends on DRM_DW_HDMI && SND
+ select SND_PCM
+ help
+ Support the I2S Audio interface which is part of the Synopsis
+ Designware HDMI block. This is used in conjunction with the
+ RK3288 HDMI driver.
+
config DRM_PTN3460
tristate "PTN3460 DP/LVDS bridge"
depends on DRM
diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
index ebc5190..4aa566a 100644
--- a/drivers/gpu/drm/bridge/Makefile
+++ b/drivers/gpu/drm/bridge/Makefile
@@ -3,3 +3,4 @@ ccflags-y := -Iinclude/drm
obj-$(CONFIG_DRM_PTN3460) += ptn3460.o
obj-$(CONFIG_DRM_DW_HDMI) += dw_hdmi.o
obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw_hdmi-ahb-audio.o
+obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw_hdmi-i2s-audio.o
diff --git a/drivers/gpu/drm/bridge/dw_hdmi-i2s-audio.c
b/drivers/gpu/drm/bridge/dw_hdmi-i2s-audio.c
new file mode 100644
index 000..e0b5b9d
--- /dev/null
+++ b/drivers/gpu/drm/bridge/dw_hdmi-i2s-audio.c
@@ -0,0 +1,412 @@
+/*
+ * DesignWare HDMI audio driver
+ *
+ * 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.
+ *
+ * Written and tested against the Designware HDMI Tx found in RK3288.
+ */
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "dw_hdmi-audio.h"
+
+#define DRIVER_NAME "dw-hdmi-i2s-audio"
+
+enum {
+ AUDIO_CONF1_DATWIDTH_MSK = 0x1F,
+ AUDIO_CONF1_DATAMODE_MSK = 0xE0,
+ AUDIO_DAIFMT_IIS = 0x0,
+ AUDIO_DAIFMT_RIGHT_J = 0x20,
+ AUDIO_DAIFMT_LEFT_J = 0x40,
+ AUDIO_DAIFMT_BURST_1 = 0x60,
+ AUDIO_DAIFMT_BURST_2 = 0x80,
+ AUDIO_CONF0_INTERFACE_MSK = BIT(5),
+ AUDIO_INPUTTYPE_IIS = 0x20,
+ AUDIO_INPUTTYPE_SPDIF = 0x00,
+ AUDIO_CONF0_I2SINEN_MSK = 0x0F,
+ AUDIO_CHANNELNUM_2 = 0x01,
+ AUDIO_CHANNELNUM_4 = 0x03,
+ AUDIO_CHANNELNUM_6 = 0x07,
+ AUDIO_CHANNELNUM_8 = 0x0F,
+ HDMI_PHY_HPD = BIT(1),
+ HDMI_PHY_STAT0 = 0x3004,
+ HDMI_AUD_CONF0 = 0x3100,
+ HDMI_AUD_CONF1 = 0x3101,
+ HDMI_AUD_INPUTCLKFS = 0x3206,
+};
+
+struct dw_audio_fmt {
+ int input_type;
+ int chan_num;
+ int sample_rate;
+ int word_length;
+ int dai_fmt;
+};
+
+struct snd_dw_hdmi {
+ struct device *dev;
+ struct dw_hdmi_audio_data data;
+
+ u8 jack_status;
+ bool is_jack_ready;
+ struct snd_soc_jack jack;
+
+ bool is_playback_status;
+ struct dw_audio_fmt fmt;
+};
+
+static void hdmi_writel(struct snd_dw_hdmi *dw, u8 val, int offset)
+{
+ writel(val, dw->data.base + (offset << 2));
+}
+
+static u8 hdmi_readl(struct snd_dw_hdmi *dw, int offset)
+{
+ return readl(dw->data.base + (offset << 2));
+}
+
+static void hdmi_modl(struct snd_dw_hdmi *dw, u8 data,
+ u8 mask, unsigned reg)
+{
+ u8 val = hdmi_readl(dw, reg) & ~mask;
+
+ val |= data & mask;
+ hdmi_writel(dw, val, reg);
+}
+
+int snd_dw_hdmi_jack_detect(struct snd_dw_hdmi *dw)
+{
+ u8 jack_status;
+
+ if (!dw->is_jack_ready)
+ return -EINVAL;
+
+ jack_status = !!(hdmi_readl(dw, HDMI_PHY_STAT0) & HDMI_PHY_HPD) ?
+ SND_JACK_LINEOUT : 0;
+
+ if (jack_status != dw->jack_status) {
+ snd_soc_jack_report(>jack, jack_status, SND_JACK_LINEOUT);
+ dw->jack_status = jack_status;
+ }
+
+ return 0;
+}
+
+static irqreturn_t snd_dw_hdmi_irq(int irq, void *dev_id)
+{
+ struct snd_dw_hdmi *dw = dev_id;
+
+ snd_dw_hdmi_jack_detect(dw);
+
+ return IRQ_HANDLED;
+}
+
+static void dw_hdmi_audio_set_fmt(struct snd_dw_hdmi *dw,
+ const struct dw_audio_fmt *fmt)
+{
+ hdmi_modl(dw, fmt->input_type, AUDIO_CONF0_INTERFACE_MSK,
+