[PATCH v4 3/8] drm/tilcdc: Add blue-and-red-crossed devicetree property

2016-09-12 Thread Rob Herring
On Thu, Sep 01, 2016 at 12:09:07PM +0300, Jyri Sarha wrote:
> Add "blue-and-red-wiring"-device tree property and update devicetree
> binding document.
> 
> The red and blue components are reversed between 24 and 16 bit modes
> on am335x LCDC output pins. To get 24 RGB format the red and blue
> wires has to be crossed and this in turn causes 16 colors output to be
> in BGR format. With straight wiring the 16 color is RGB and 24 bit is
> BGR.
> 
> The new property describes whether the red and blue wires are crossed
> or not. If the property is not present or its value is not recognized
> the legacy mode is assumed. The legacy configuration supports RGB565,
> RGB888 and XRGB formats. However, depending on wiring, the red and
> blue colors are swapped in either 16 or 24-bit color modes.
> 
> For more details see section 3.1.1 in AM335x Silicon Errata:
> http://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=sprz360
> 
> Signed-off-by: Jyri Sarha 
> ---
>  .../devicetree/bindings/display/tilcdc/tilcdc.txt  | 22 
>  drivers/gpu/drm/tilcdc/tilcdc_drv.c| 41 
> ++
>  drivers/gpu/drm/tilcdc/tilcdc_drv.h|  4 +++
>  drivers/gpu/drm/tilcdc/tilcdc_plane.c  |  9 ++---
>  4 files changed, 70 insertions(+), 6 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/display/tilcdc/tilcdc.txt 
> b/Documentation/devicetree/bindings/display/tilcdc/tilcdc.txt
> index 6efa4c5..a5007aa 100644
> --- a/Documentation/devicetree/bindings/display/tilcdc/tilcdc.txt
> +++ b/Documentation/devicetree/bindings/display/tilcdc/tilcdc.txt
> @@ -17,6 +17,18 @@ Optional properties:
> the lcd controller.
>   - max-pixelclock: The maximum pixel clock that can be supported
> by the lcd controller in KHz.
> + - blue-and-red-wiring: Recognized values "default", "straight" or

Need to drop default from here. With that,

Acked-by: Rob Herring 

> +   "crossed". This property deals with the LCDC revision 2 (found on
> +   AM335x) color errata [1].
> +- "straight" indicates normal wiring that supports RGB565,
> +  BGR888, and XBGR color formats.
> +- "crossed" indicates wiring that has blue and red wires
> +  crossed. This setup supports BGR565, RGB888 and XRGB
> +  formats.
> +- If the property is not present or its value is not recognized
> +  the legacy mode is assumed. This configuration supports RGB565,
> +  RGB888 and XRGB formats. However, depending on wiring, the red
> +  and blue colors are swapped in either 16 or 24-bit color modes.
>  
>  Optional nodes:
>  
> @@ -28,6 +40,14 @@ Optional nodes:
> Documentation/devicetree/bindings/display/tilcdc/tfp410.txt for connecting
> tfp410 DVI encoder or lcd panel to lcdc
>  
> +[1] There is an errata about AM335x color wiring. For 16-bit color mode
> +the wires work as they should (LCD_DATA[0:4] is for Blue[3:7]),
> +but for 24 bit color modes the wiring of blue and red components is
> +crossed and LCD_DATA[0:4] is for Red[3:7] and LCD_DATA[11:15] is
> +for Blue[3-7]. For more details see section 3.1.1 in AM335x
> +Silicon Errata:
> +
> http://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=sprz360
> +
>  Example:
>  
>   fb: fb at 4830e000 {
> @@ -37,6 +57,8 @@ Example:
>   interrupts = <36>;
>   ti,hwmods = "lcdc";
>  
> + blue-and-red-wiring = "crossed";
> +
>   port {
>   lcdc_0: endpoint at 0 {
>   remote-endpoint = <_0>;
> diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c 
> b/drivers/gpu/drm/tilcdc/tilcdc_drv.c
> index e45c268..ed4dc5c 100644
> --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c
> +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c
> @@ -33,6 +33,20 @@
>  
>  static LIST_HEAD(module_list);
>  
> +static const u32 tilcdc_rev1_formats[] = { DRM_FORMAT_RGB565 };
> +
> +static const u32 tilcdc_straight_formats[] = { DRM_FORMAT_RGB565,
> +DRM_FORMAT_BGR888,
> +DRM_FORMAT_XBGR };
> +
> +static const u32 tilcdc_crossed_formats[] = { DRM_FORMAT_BGR565,
> +   DRM_FORMAT_RGB888,
> +   DRM_FORMAT_XRGB };
> +
> +static const u32 tilcdc_legacy_formats[] = { DRM_FORMAT_RGB565,
> +  DRM_FORMAT_RGB888,
> +  DRM_FORMAT_XRGB };
> +
>  void tilcdc_module_init(struct tilcdc_module *mod, const char *name,
>   const struct tilcdc_module_ops *funcs)
>  {
> @@ -318,6 +332,33 @@ static int tilcdc_load(struct drm_device *dev, unsigned 
> long flags)
>  
>   pm_runtime_put_sync(dev->dev);
>  
> + if (priv->rev == 1) {
> + DBG("Revision 1 LCDC supports only RGB565 format");
> + priv->pixelformats = tilcdc_rev1_formats;

[PATCH v4 3/8] drm/tilcdc: Add blue-and-red-crossed devicetree property

2016-09-01 Thread Jyri Sarha
Add "blue-and-red-wiring"-device tree property and update devicetree
binding document.

The red and blue components are reversed between 24 and 16 bit modes
on am335x LCDC output pins. To get 24 RGB format the red and blue
wires has to be crossed and this in turn causes 16 colors output to be
in BGR format. With straight wiring the 16 color is RGB and 24 bit is
BGR.

The new property describes whether the red and blue wires are crossed
or not. If the property is not present or its value is not recognized
the legacy mode is assumed. The legacy configuration supports RGB565,
RGB888 and XRGB formats. However, depending on wiring, the red and
blue colors are swapped in either 16 or 24-bit color modes.

For more details see section 3.1.1 in AM335x Silicon Errata:
http://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=sprz360

Signed-off-by: Jyri Sarha 
---
 .../devicetree/bindings/display/tilcdc/tilcdc.txt  | 22 
 drivers/gpu/drm/tilcdc/tilcdc_drv.c| 41 ++
 drivers/gpu/drm/tilcdc/tilcdc_drv.h|  4 +++
 drivers/gpu/drm/tilcdc/tilcdc_plane.c  |  9 ++---
 4 files changed, 70 insertions(+), 6 deletions(-)

diff --git a/Documentation/devicetree/bindings/display/tilcdc/tilcdc.txt 
b/Documentation/devicetree/bindings/display/tilcdc/tilcdc.txt
index 6efa4c5..a5007aa 100644
--- a/Documentation/devicetree/bindings/display/tilcdc/tilcdc.txt
+++ b/Documentation/devicetree/bindings/display/tilcdc/tilcdc.txt
@@ -17,6 +17,18 @@ Optional properties:
the lcd controller.
  - max-pixelclock: The maximum pixel clock that can be supported
by the lcd controller in KHz.
+ - blue-and-red-wiring: Recognized values "default", "straight" or
+   "crossed". This property deals with the LCDC revision 2 (found on
+   AM335x) color errata [1].
+- "straight" indicates normal wiring that supports RGB565,
+  BGR888, and XBGR color formats.
+- "crossed" indicates wiring that has blue and red wires
+  crossed. This setup supports BGR565, RGB888 and XRGB
+  formats.
+- If the property is not present or its value is not recognized
+  the legacy mode is assumed. This configuration supports RGB565,
+  RGB888 and XRGB formats. However, depending on wiring, the red
+  and blue colors are swapped in either 16 or 24-bit color modes.

 Optional nodes:

@@ -28,6 +40,14 @@ Optional nodes:
Documentation/devicetree/bindings/display/tilcdc/tfp410.txt for connecting
tfp410 DVI encoder or lcd panel to lcdc

+[1] There is an errata about AM335x color wiring. For 16-bit color mode
+the wires work as they should (LCD_DATA[0:4] is for Blue[3:7]),
+but for 24 bit color modes the wiring of blue and red components is
+crossed and LCD_DATA[0:4] is for Red[3:7] and LCD_DATA[11:15] is
+for Blue[3-7]. For more details see section 3.1.1 in AM335x
+Silicon Errata:
+
http://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=sprz360
+
 Example:

fb: fb at 4830e000 {
@@ -37,6 +57,8 @@ Example:
interrupts = <36>;
ti,hwmods = "lcdc";

+   blue-and-red-wiring = "crossed";
+
port {
lcdc_0: endpoint at 0 {
remote-endpoint = <_0>;
diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c 
b/drivers/gpu/drm/tilcdc/tilcdc_drv.c
index e45c268..ed4dc5c 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c
@@ -33,6 +33,20 @@

 static LIST_HEAD(module_list);

+static const u32 tilcdc_rev1_formats[] = { DRM_FORMAT_RGB565 };
+
+static const u32 tilcdc_straight_formats[] = { DRM_FORMAT_RGB565,
+  DRM_FORMAT_BGR888,
+  DRM_FORMAT_XBGR };
+
+static const u32 tilcdc_crossed_formats[] = { DRM_FORMAT_BGR565,
+ DRM_FORMAT_RGB888,
+ DRM_FORMAT_XRGB };
+
+static const u32 tilcdc_legacy_formats[] = { DRM_FORMAT_RGB565,
+DRM_FORMAT_RGB888,
+DRM_FORMAT_XRGB };
+
 void tilcdc_module_init(struct tilcdc_module *mod, const char *name,
const struct tilcdc_module_ops *funcs)
 {
@@ -318,6 +332,33 @@ static int tilcdc_load(struct drm_device *dev, unsigned 
long flags)

pm_runtime_put_sync(dev->dev);

+   if (priv->rev == 1) {
+   DBG("Revision 1 LCDC supports only RGB565 format");
+   priv->pixelformats = tilcdc_rev1_formats;
+   priv->num_pixelformats = ARRAY_SIZE(tilcdc_rev1_formats);
+   } else {
+   const char *str = "\0";
+
+   of_property_read_string(node, "blue-and-red-wiring", );
+   if (0 == strcmp(str, "crossed")) {
+   DBG("Configured for crossed blue and red