Re: [U-Boot] [PATCH u-boot 03/11] video: dw_hdmi: add support for color conversion

2019-01-28 Thread Anatolij Gustschin
On Tue, 15 Jan 2019 17:17:51 +0100
Neil Armstrong narmstr...@baylibre.com wrote:

> From: Jorge Ramirez-Ortiz 
> 
> Some IPs like the meson VPU can only feed a particular pixel format to
> dw_hdmi. As of now, the driver is hardcoded to use RGB888 as input.
> 
> This commit enables different pixel format inputs, with the appropriate
> CSC configuration.
> 
> Signed-off-by: Jorge Ramire-Ortiz 
> Signed-off-by: Maxime Jourdan 
> Signed-off-by: Neil Armstrong 

Reviewed-by: Anatolij Gustschin 

--
Anatolij
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH u-boot 03/11] video: dw_hdmi: add support for color conversion

2019-01-15 Thread Neil Armstrong
From: Jorge Ramirez-Ortiz 

Some IPs like the meson VPU can only feed a particular pixel format to
dw_hdmi. As of now, the driver is hardcoded to use RGB888 as input.

This commit enables different pixel format inputs, with the appropriate
CSC configuration.

Signed-off-by: Jorge Ramire-Ortiz 
Signed-off-by: Maxime Jourdan 
Signed-off-by: Neil Armstrong 
---
 drivers/video/dw_hdmi.c| 253 -
 include/dw_hdmi.h  |  72 +++
 include/media_bus_format.h | 156 +++
 3 files changed, 480 insertions(+), 1 deletion(-)
 create mode 100644 include/media_bus_format.h

diff --git a/drivers/video/dw_hdmi.c b/drivers/video/dw_hdmi.c
index e03f24fa98..463436edf3 100644
--- a/drivers/video/dw_hdmi.c
+++ b/drivers/video/dw_hdmi.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "dw_hdmi.h"
 
 struct tmds_n_cts {
@@ -52,6 +53,24 @@ static const struct tmds_n_cts n_cts_table[] = {
}
 };
 
+static const u16 csc_coeff_default[3][4] = {
+   { 0x2000, 0x, 0x, 0x },
+   { 0x, 0x2000, 0x, 0x },
+   { 0x, 0x, 0x2000, 0x }
+};
+
+static const u16 csc_coeff_rgb_in_eitu601[3][4] = {
+   { 0x2591, 0x1322, 0x074b, 0x },
+   { 0x6535, 0x2000, 0x7acc, 0x0200 },
+   { 0x6acd, 0x7534, 0x2000, 0x0200 }
+};
+
+static const u16 csc_coeff_rgb_out_eitu601[3][4] = {
+   { 0x2000, 0x6926, 0x74fd, 0x010e },
+   { 0x2000, 0x2cdd, 0x, 0x7e9a },
+   { 0x2000, 0x, 0x38b4, 0x7e3b }
+};
+
 static void dw_hdmi_write(struct dw_hdmi *hdmi, u8 val, int offset)
 {
switch (hdmi->reg_io_width) {
@@ -162,9 +181,52 @@ static void hdmi_audio_set_samplerate(struct dw_hdmi 
*hdmi, u32 pixel_clk)
  */
 static void hdmi_video_sample(struct dw_hdmi *hdmi)
 {
-   u32 color_format = 0x01;
+   u32 color_format;
uint val;
 
+   switch (hdmi->hdmi_data.enc_in_bus_format) {
+   case MEDIA_BUS_FMT_RGB888_1X24:
+   color_format = 0x01;
+   break;
+   case MEDIA_BUS_FMT_RGB101010_1X30:
+   color_format = 0x03;
+   break;
+   case MEDIA_BUS_FMT_RGB121212_1X36:
+   color_format = 0x05;
+   break;
+   case MEDIA_BUS_FMT_RGB161616_1X48:
+   color_format = 0x07;
+   break;
+   case MEDIA_BUS_FMT_YUV8_1X24:
+   case MEDIA_BUS_FMT_UYYVYY8_0_5X24:
+   color_format = 0x09;
+   break;
+   case MEDIA_BUS_FMT_YUV10_1X30:
+   case MEDIA_BUS_FMT_UYYVYY10_0_5X30:
+   color_format = 0x0B;
+   break;
+   case MEDIA_BUS_FMT_YUV12_1X36:
+   case MEDIA_BUS_FMT_UYYVYY12_0_5X36:
+   color_format = 0x0D;
+   break;
+   case MEDIA_BUS_FMT_YUV16_1X48:
+   case MEDIA_BUS_FMT_UYYVYY16_0_5X48:
+   color_format = 0x0F;
+   break;
+   case MEDIA_BUS_FMT_UYVY8_1X16:
+   color_format = 0x16;
+   break;
+   case MEDIA_BUS_FMT_UYVY10_1X20:
+   color_format = 0x14;
+   break;
+   case MEDIA_BUS_FMT_UYVY12_1X24:
+   color_format = 0x12;
+   break;
+   default:
+   color_format = 0x01;
+   break;
+   }
+
val = HDMI_TX_INVID0_INTERNAL_DE_GENERATOR_DISABLE |
  ((color_format << HDMI_TX_INVID0_VIDEO_MAPPING_OFFSET) &
  HDMI_TX_INVID0_VIDEO_MAPPING_MASK);
@@ -457,6 +519,180 @@ static void hdmi_av_composer(struct dw_hdmi *hdmi,
hdmi_write(hdmi, edid->vsync_len.typ, HDMI_FC_VSYNCINWIDTH);
 }
 
+static bool hdmi_bus_fmt_is_rgb(unsigned int bus_format)
+{
+   switch (bus_format) {
+   case MEDIA_BUS_FMT_RGB888_1X24:
+   case MEDIA_BUS_FMT_RGB101010_1X30:
+   case MEDIA_BUS_FMT_RGB121212_1X36:
+   case MEDIA_BUS_FMT_RGB161616_1X48:
+   return true;
+
+   default:
+   return false;
+   }
+}
+
+static bool hdmi_bus_fmt_is_yuv444(unsigned int bus_format)
+{
+   switch (bus_format) {
+   case MEDIA_BUS_FMT_YUV8_1X24:
+   case MEDIA_BUS_FMT_YUV10_1X30:
+   case MEDIA_BUS_FMT_YUV12_1X36:
+   case MEDIA_BUS_FMT_YUV16_1X48:
+   return true;
+
+   default:
+   return false;
+   }
+}
+
+static bool hdmi_bus_fmt_is_yuv422(unsigned int bus_format)
+{
+   switch (bus_format) {
+   case MEDIA_BUS_FMT_UYVY8_1X16:
+   case MEDIA_BUS_FMT_UYVY10_1X20:
+   case MEDIA_BUS_FMT_UYVY12_1X24:
+   return true;
+
+   default:
+   return false;
+   }
+}
+
+static int is_color_space_interpolation(struct dw_hdmi *hdmi)
+{
+   if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_in_bus_format))
+   return 0;
+
+   if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format) ||
+   hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format))
+   return 1;
+
+   return