[PATCH v3] drm: bridge: add DesignWare HDMI I2S audio support

2016-11-08 Thread Kuninori Morimoto

Hi Russell

> > > This is wrong.  If platform is NULL, PTR_ERR() will return zero, which
> > > will be interpreted as success.  Please, avoid using IS_ERR_OR_NULL(),
> > > it leads to exactly this kind of cockup - and it's unnecessary here
> > > because platform_device_register_full() does not return NULL.
> > 
> > Thank you for your feedback.
> > Before sending v4 patch, I would like to confirm. Do you meand this ?
> > # use IS_ERR() instead of IS_ERR_OR_NULL()
> > 
> > platform = platform_device_register_full();
> > if (IS_ERR(platform))
> > return PTR_ERR(platform);
> 
> Yes, that's exactly correct.

Thanks !
I will send v4 patch

Best regards
---
Kuninori Morimoto


[PATCH v3] drm: bridge: add DesignWare HDMI I2S audio support

2016-11-07 Thread Russell King - ARM Linux
On Mon, Nov 07, 2016 at 03:50:00AM +, Kuninori Morimoto wrote:
> 
> Hi Russell
> 
> > > + platform = platform_device_register_full();
> > > + if (IS_ERR_OR_NULL(platform))
> > > + return PTR_ERR(platform);
> > 
> > This is wrong.  If platform is NULL, PTR_ERR() will return zero, which
> > will be interpreted as success.  Please, avoid using IS_ERR_OR_NULL(),
> > it leads to exactly this kind of cockup - and it's unnecessary here
> > because platform_device_register_full() does not return NULL.
> 
> Thank you for your feedback.
> Before sending v4 patch, I would like to confirm. Do you meand this ?
> # use IS_ERR() instead of IS_ERR_OR_NULL()
> 
>   platform = platform_device_register_full();
>   if (IS_ERR(platform))
>   return PTR_ERR(platform);

Yes, that's exactly correct.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.


[PATCH v3] drm: bridge: add DesignWare HDMI I2S audio support

2016-11-07 Thread Kuninori Morimoto

Hi Russell

> > +   platform = platform_device_register_full();
> > +   if (IS_ERR_OR_NULL(platform))
> > +   return PTR_ERR(platform);
> 
> This is wrong.  If platform is NULL, PTR_ERR() will return zero, which
> will be interpreted as success.  Please, avoid using IS_ERR_OR_NULL(),
> it leads to exactly this kind of cockup - and it's unnecessary here
> because platform_device_register_full() does not return NULL.

Thank you for your feedback.
Before sending v4 patch, I would like to confirm. Do you meand this ?
# use IS_ERR() instead of IS_ERR_OR_NULL()

platform = platform_device_register_full();
if (IS_ERR(platform))
return PTR_ERR(platform);


[PATCH v3] drm: bridge: add DesignWare HDMI I2S audio support

2016-11-02 Thread Russell King - ARM Linux
On Wed, Nov 02, 2016 at 01:18:35AM +, Kuninori Morimoto wrote:
> + platform = platform_device_register_full();
> + if (IS_ERR_OR_NULL(platform))
> + return PTR_ERR(platform);

This is wrong.  If platform is NULL, PTR_ERR() will return zero, which
will be interpreted as success.  Please, avoid using IS_ERR_OR_NULL(),
it leads to exactly this kind of cockup - and it's unnecessary here
because platform_device_register_full() does not return NULL.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.


[PATCH v3] drm: bridge: add DesignWare HDMI I2S audio support

2016-11-02 Thread Kuninori Morimoto

From: Kuninori Morimoto 

Current dw-hdmi is supporting sound via AHB bus, but it has
I2S audio feature too. This patch adds I2S audio support to dw-hdmi.
This HDMI I2S is supported by using ALSA SoC common HDMI encoder
driver.

Tested-by: Jose Abreu 
Signed-off-by: Kuninori Morimoto 
---
v2 -> v3

 - add .remove and call platform_device_unregister()
 - add missing Tested-by: Jose Abreu on log

 drivers/gpu/drm/bridge/Kconfig |   8 ++
 drivers/gpu/drm/bridge/Makefile|   1 +
 drivers/gpu/drm/bridge/dw-hdmi-audio.h |   7 ++
 drivers/gpu/drm/bridge/dw-hdmi-i2s-audio.c | 142 +
 drivers/gpu/drm/bridge/dw-hdmi.c   |  22 -
 drivers/gpu/drm/bridge/dw-hdmi.h   |  21 +
 6 files changed, 199 insertions(+), 2 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 10e12e7..3129f8d 100644
--- a/drivers/gpu/drm/bridge/Kconfig
+++ b/drivers/gpu/drm/bridge/Kconfig
@@ -39,6 +39,14 @@ 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
+   select SND_SOC_HDMI_CODEC
+   help
+ Support the I2S Audio interface which is part of the Synopsis
+ Designware HDMI block.
+
 config DRM_NXP_PTN3460
tristate "NXP PTN3460 DP/LVDS bridge"
depends on OF
diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
index cdf3a3c..9a54f2a 100644
--- a/drivers/gpu/drm/bridge/Makefile
+++ b/drivers/gpu/drm/bridge/Makefile
@@ -4,6 +4,7 @@ obj-$(CONFIG_DRM_ANALOGIX_ANX78XX) += analogix-anx78xx.o
 obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.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
 obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
 obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
 obj-$(CONFIG_DRM_SII902X) += sii902x.o
diff --git a/drivers/gpu/drm/bridge/dw-hdmi-audio.h 
b/drivers/gpu/drm/bridge/dw-hdmi-audio.h
index 91f631b..fd1f745 100644
--- a/drivers/gpu/drm/bridge/dw-hdmi-audio.h
+++ b/drivers/gpu/drm/bridge/dw-hdmi-audio.h
@@ -11,4 +11,11 @@ struct dw_hdmi_audio_data {
u8 *eld;
 };

+struct dw_hdmi_i2s_audio_data {
+   struct dw_hdmi *hdmi;
+
+   void (*write)(struct dw_hdmi *hdmi, u8 val, int offset);
+   u8 (*read)(struct dw_hdmi *hdmi, int offset);
+};
+
 #endif
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..44880d8
--- /dev/null
+++ b/drivers/gpu/drm/bridge/dw-hdmi-i2s-audio.c
@@ -0,0 +1,142 @@
+/*
+ * dw-hdmi-i2s-audio.c
+ *
+ * Copyright (c) 2016 Kuninori Morimoto 
+ *
+ * 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.
+ */
+#include 
+
+#include 
+
+#include "dw-hdmi.h"
+#include "dw-hdmi-audio.h"
+
+#define DRIVER_NAME "dw-hdmi-i2s-audio"
+
+static inline void hdmi_write(struct dw_hdmi_i2s_audio_data *audio,
+ u8 val, int offset)
+{
+   struct dw_hdmi *hdmi = audio->hdmi;
+
+   audio->write(hdmi, val, offset);
+}
+
+static inline u8 hdmi_read(struct dw_hdmi_i2s_audio_data *audio, int offset)
+{
+   struct dw_hdmi *hdmi = audio->hdmi;
+
+   return audio->read(hdmi, offset);
+}
+
+static int dw_hdmi_i2s_hw_params(struct device *dev, void *data,
+struct hdmi_codec_daifmt *fmt,
+struct hdmi_codec_params *hparms)
+{
+   struct dw_hdmi_i2s_audio_data *audio = data;
+   struct dw_hdmi *hdmi = audio->hdmi;
+   u8 conf0 = 0;
+   u8 conf1 = 0;
+   u8 inputclkfs = 0;
+
+   /* it cares I2S only */
+   if ((fmt->fmt != HDMI_I2S) ||
+   (fmt->bit_clk_master | fmt->frame_clk_master)) {
+   dev_err(dev, "unsupported format/settings\n");
+   return -EINVAL;
+   }
+
+   inputclkfs  = HDMI_AUD_INPUTCLKFS_64FS;
+   conf0   = HDMI_AUD_CONF0_I2S_ALL_ENABLE;
+
+   switch (hparms->sample_width) {
+   case 16:
+   conf1 = HDMI_AUD_CONF1_WIDTH_16;
+   break;
+   case 24:
+   case 32:
+   conf1 = HDMI_AUD_CONF1_WIDTH_24;
+   break;
+   }
+
+   dw_hdmi_set_sample_rate(hdmi, hparms->sample_rate);
+
+   hdmi_write(audio, inputclkfs, HDMI_AUD_INPUTCLKFS);
+   hdmi_write(audio, conf0, HDMI_AUD_CONF0);
+   hdmi_write(audio, conf1, HDMI_AUD_CONF1);
+
+   dw_hdmi_audio_enable(hdmi);
+
+   return 0;
+}
+
+static void dw_hdmi_i2s_audio_shutdown(struct device