[PATCH 9/9] drm: bridge/dw_hdmi-i2s-audio: add audio driver

2015-08-11 Thread Yakir Yang
Hi Russell,

在 2015/8/10 23:48, Russell King - ARM Linux 写道:
> On Sat, Aug 08, 2015 at 05:10:47PM +0100, Russell King wrote:
>> From: Yakir Yang 
>>
>> 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".
>>
>> [Fixed IRQ name, MODULE_DESCRIPTION, MODULE_ALIAS in
>>   dw-hdmi-i2s-audio.c, and platform device name in dw-hdmi.c --rmk]
>>
>> Signed-off-by: Yakir Yang 
>> Signed-off-by: Russell King 
> I'm dropping this patch after all as it no longer builds against modern
> kernels due to the reference to the removed snd_soc_jack_new().  Its
> replacement is at card level, and I don't think it's a simple case of
> replacing it here.

Hmm... I would rather to fix it in my side, and then I could rebase on 
your series, is it okay ?

- Yakir

>> +static int snd_dw_hdmi_audio_probe(struct snd_soc_codec *codec)
>> +{
>> +struct snd_dw_hdmi *dw = snd_soc_codec_get_drvdata(codec);
>> +int ret;
>> +
>> +ret = snd_soc_jack_new(codec, "dw Jack", SND_JACK_LINEOUT,
>> +   >jack);
> ...
>> +static const struct snd_soc_codec_driver dw_hdmi_audio = {
>> +.probe = snd_dw_hdmi_audio_probe,
>> +.dapm_widgets = snd_dw_hdmi_audio_widgets,
>> +.num_dapm_widgets = ARRAY_SIZE(snd_dw_hdmi_audio_widgets),
>> +.dapm_routes = snd_dw_hdmi_audio_routes,
>> +.num_dapm_routes = ARRAY_SIZE(snd_dw_hdmi_audio_routes),
>> +};
>> +
>> +static int dw_hdmi_audio_probe(struct platform_device *pdev)
>> +{
>> +struct dw_hdmi_audio_data *data = pdev->dev.platform_data;
>> +struct snd_dw_hdmi *dw;
>> +int ret;
>> +
>> +dw = devm_kzalloc(>dev, sizeof(*dw), GFP_KERNEL);
>> +if (!dw)
>> +return -ENOMEM;
>> +
>> +dw->data = *data;
>> +dw->dev = >dev;
>> +dw->is_jack_ready = false;
>> +platform_set_drvdata(pdev, dw);
>> +
>> +ret = request_irq(dw->data.irq, snd_dw_hdmi_irq, IRQF_SHARED,
>> +  DRIVER_NAME, dw);
>> +if (ret) {
>> +dev_err(>dev, "request irq failed (%d)\n", ret);
>> +return -EINVAL;
>> +}
>> +
>> +ret = snd_soc_register_codec(>dev, _hdmi_audio,
>> + _hdmi_audio_dai, 1);




[PATCH 9/9] drm: bridge/dw_hdmi-i2s-audio: add audio driver

2015-08-10 Thread Russell King - ARM Linux
On Sat, Aug 08, 2015 at 05:10:47PM +0100, Russell King wrote:
> From: Yakir Yang 
> 
> 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".
> 
> [Fixed IRQ name, MODULE_DESCRIPTION, MODULE_ALIAS in
>  dw-hdmi-i2s-audio.c, and platform device name in dw-hdmi.c --rmk]
> 
> Signed-off-by: Yakir Yang 
> Signed-off-by: Russell King 

I'm dropping this patch after all as it no longer builds against modern
kernels due to the reference to the removed snd_soc_jack_new().  Its
replacement is at card level, and I don't think it's a simple case of
replacing it here.

> +static int snd_dw_hdmi_audio_probe(struct snd_soc_codec *codec)
> +{
> + struct snd_dw_hdmi *dw = snd_soc_codec_get_drvdata(codec);
> + int ret;
> +
> + ret = snd_soc_jack_new(codec, "dw Jack", SND_JACK_LINEOUT,
> +>jack);
...
> +static const struct snd_soc_codec_driver dw_hdmi_audio = {
> + .probe = snd_dw_hdmi_audio_probe,
> + .dapm_widgets = snd_dw_hdmi_audio_widgets,
> + .num_dapm_widgets = ARRAY_SIZE(snd_dw_hdmi_audio_widgets),
> + .dapm_routes = snd_dw_hdmi_audio_routes,
> + .num_dapm_routes = ARRAY_SIZE(snd_dw_hdmi_audio_routes),
> +};
> +
> +static int dw_hdmi_audio_probe(struct platform_device *pdev)
> +{
> + struct dw_hdmi_audio_data *data = pdev->dev.platform_data;
> + struct snd_dw_hdmi *dw;
> + int ret;
> +
> + dw = devm_kzalloc(>dev, sizeof(*dw), GFP_KERNEL);
> + if (!dw)
> + return -ENOMEM;
> +
> + dw->data = *data;
> + dw->dev = >dev;
> + dw->is_jack_ready = false;
> + platform_set_drvdata(pdev, dw);
> +
> + ret = request_irq(dw->data.irq, snd_dw_hdmi_irq, IRQF_SHARED,
> +   DRIVER_NAME, dw);
> + if (ret) {
> + dev_err(>dev, "request irq failed (%d)\n", ret);
> + return -EINVAL;
> + }
> +
> + ret = snd_soc_register_codec(>dev, _hdmi_audio,
> +  _hdmi_audio_dai, 1);

-- 
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.


[PATCH 9/9] drm: bridge/dw_hdmi-i2s-audio: add audio driver

2015-08-08 Thread Russell King
From: Yakir Yang 
To: linux-rockchip at lists.infradead.org,alsa-devel at 
alsa-project.org,dri-devel at lists.freedesktop.org,linux-kernel at 
vger.kernel.org,linux-arm-kernel at lists.infradead.org

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".

[Fixed IRQ name, MODULE_DESCRIPTION, MODULE_ALIAS in
 dw-hdmi-i2s-audio.c, and platform device name in dw-hdmi.c --rmk]

Signed-off-by: Yakir Yang 
Signed-off-by: Russell King 
---
 drivers/gpu/drm/bridge/Kconfig |   9 +
 drivers/gpu/drm/bridge/Makefile|   1 +
 drivers/gpu/drm/bridge/dw_hdmi-i2s-audio.c | 398 +
 drivers/gpu/drm/bridge/dw_hdmi.c   |  24 +-
 drivers/gpu/drm/bridge/dw_hdmi.h   |   3 +
 5 files changed, 426 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 204861bfb867..59e3f24c4918 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 eb80dbbb8365..65a12390844a 100644
--- a/drivers/gpu/drm/bridge/Makefile
+++ b/drivers/gpu/drm/bridge/Makefile
@@ -4,3 +4,4 @@ obj-$(CONFIG_DRM_PS8622) += ps8622.o
 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 ..62d3d33642d0
--- /dev/null
+++ b/drivers/gpu/drm/bridge/dw_hdmi-i2s-audio.c
@@ -0,0 +1,398 @@
+/*
+ * 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;
+
+   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;
+
+   snd_soc_jack_report(>jack, jack_status, SND_JACK_LINEOUT);
+
+   return 0;
+}
+
+static irqreturn_t snd_dw_hdmi_irq(int irq, void *dev_id)
+{
+   struct snd_dw_hdmi