Re: [PATCH v2 2/4] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-10 Thread Rob Herring
On Tue, Aug 01, 2017 at 05:11:48PM -0500, David Lechner wrote:
> LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
> module for the ST7586 controller with parameters for the EV3 LCD display.
> 
> Signed-off-by: David Lechner 
> ---
>  .../devicetree/bindings/display/st7586.txt |  26 +

Please split bindings to a separate patch.

>  drivers/gpu/drm/tinydrm/Kconfig|  10 +
>  drivers/gpu/drm/tinydrm/Makefile   |   1 +
>  drivers/gpu/drm/tinydrm/st7586.c   | 579 
> +
>  include/drm/tinydrm/st7586.h   |  34 ++
>  5 files changed, 650 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/display/st7586.txt
>  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c
>  create mode 100644 include/drm/tinydrm/st7586.h
> 
> diff --git a/Documentation/devicetree/bindings/display/st7586.txt 
> b/Documentation/devicetree/bindings/display/st7586.txt
> new file mode 100644
> index 000..acf784aa
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/display/st7586.txt
> @@ -0,0 +1,26 @@
> +Sitronix ST7586 display panel
> +
> +Required properties:
> +- compatible:"lego,ev3-lcd".
> +
> +The node for this driver must be a child node of a SPI controller, hence
> +all mandatory properties described in ../spi/spi-bus.txt must be specified.
> +
> +Optional properties:
> +- dc-gpios:  D/C pin. The presence/absence of this GPIO determines
> + the panel interface mode (IM[3:0] pins):
> + - present: IM=x110 4-wire 8-bit data serial interface
> + - absent:  IM=x101 3-wire 9-bit data serial interface

This is a Lego specific pin which in turn drives IM (or IF) signals? 
This should have a vendor prefix with either lego or Sitronix depending 
on the answer.

Presence/absence doesn't sense. Doesn't the state of the GPIO line 
matter? You should just say if not present, the interface defaults to 
3-wire mode.

> +- reset-gpios:   Reset pin
> +- power-supply:  A regulator node for the supply voltage.
> +- backlight: phandle of the backlight device attached to the panel
> +- rotation:  panel rotation in degrees counter clockwise (0,90,180,270)
> +
> +Example:
> + display@0{
> + compatible = "lego,ev3-lcd";
> + reg = <0>;
> + spi-max-frequency = <1000>;
> + dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
> + reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
> + };


Re: [PATCH v2 2/4] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-10 Thread Rob Herring
On Tue, Aug 01, 2017 at 05:11:48PM -0500, David Lechner wrote:
> LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
> module for the ST7586 controller with parameters for the EV3 LCD display.
> 
> Signed-off-by: David Lechner 
> ---
>  .../devicetree/bindings/display/st7586.txt |  26 +

Please split bindings to a separate patch.

>  drivers/gpu/drm/tinydrm/Kconfig|  10 +
>  drivers/gpu/drm/tinydrm/Makefile   |   1 +
>  drivers/gpu/drm/tinydrm/st7586.c   | 579 
> +
>  include/drm/tinydrm/st7586.h   |  34 ++
>  5 files changed, 650 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/display/st7586.txt
>  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c
>  create mode 100644 include/drm/tinydrm/st7586.h
> 
> diff --git a/Documentation/devicetree/bindings/display/st7586.txt 
> b/Documentation/devicetree/bindings/display/st7586.txt
> new file mode 100644
> index 000..acf784aa
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/display/st7586.txt
> @@ -0,0 +1,26 @@
> +Sitronix ST7586 display panel
> +
> +Required properties:
> +- compatible:"lego,ev3-lcd".
> +
> +The node for this driver must be a child node of a SPI controller, hence
> +all mandatory properties described in ../spi/spi-bus.txt must be specified.
> +
> +Optional properties:
> +- dc-gpios:  D/C pin. The presence/absence of this GPIO determines
> + the panel interface mode (IM[3:0] pins):
> + - present: IM=x110 4-wire 8-bit data serial interface
> + - absent:  IM=x101 3-wire 9-bit data serial interface

This is a Lego specific pin which in turn drives IM (or IF) signals? 
This should have a vendor prefix with either lego or Sitronix depending 
on the answer.

Presence/absence doesn't sense. Doesn't the state of the GPIO line 
matter? You should just say if not present, the interface defaults to 
3-wire mode.

> +- reset-gpios:   Reset pin
> +- power-supply:  A regulator node for the supply voltage.
> +- backlight: phandle of the backlight device attached to the panel
> +- rotation:  panel rotation in degrees counter clockwise (0,90,180,270)
> +
> +Example:
> + display@0{
> + compatible = "lego,ev3-lcd";
> + reg = <0>;
> + spi-max-frequency = <1000>;
> + dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
> + reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
> + };


Re: [PATCH v2 2/4] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-02 Thread Noralf Trønnes


Den 02.08.2017 18.24, skrev David Lechner:

On 08/02/2017 08:03 AM, Noralf Trønnes wrote:



Please use tinydrm_xrgb_to_gray8().


I considered this, but is seems excessive to loop through the entire 
fb twice just to make a 4x6 cursor blink.




Yes, you're right about that.

Can you change tinydrm_xrgb_to_gray8 to match the other
copy/conversion functions so we can pass it a clip rectangle:

int tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr,
struct drm_framebuffer *fb,
struct drm_clip_rect *clip)

And move the import_attach part to the driver (repaper).
repaper doesn't do partial updates, so pass a full clip.


You should use this function to enable the regulator and init the
controller. Don't look at mi0283qt it should have been fixed.


ACK. But this is why I was not keen on writing a standalone driver. I 
know some things about kernel development, but not everything. How am 
I supposed to know what is OK to copy from other drivers and what is not? 


You can't know, and it's part of the review process to sort that out.
That being said, I really should have fixed mi0283qt, because it will
be copied...

And if I am going to be put down as the maintainer of this driver, it 
bothers me that I don't know so much about how it all works.




You don't need to know all the details. If I make a change, you can
assume that I know what I'm doing and ack it, but I need someone to
look at my patches, I can't apply my own patches without anyone looking
at it, we all make mistakes. And if someone else sends a patch and you
don't know if it is good or not, just ping me and I'll look at it.
Either way I have to look at all tinydrm patches before applying them.
I'm not keen on being default maintainer on drivers that I can't test.
The upside of being a maintainer is that you control the future of the
driver, what changes goes in.

And I'm kind of in the same boat as you, I know tinydrm, but drm is
very complex and I don't know half of what's going on. If I'm stuck or
out of my league, I have to ask for help. Like with adding drm formats.

Noralf.



Re: [PATCH v2 2/4] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-02 Thread Noralf Trønnes


Den 02.08.2017 18.24, skrev David Lechner:

On 08/02/2017 08:03 AM, Noralf Trønnes wrote:



Please use tinydrm_xrgb_to_gray8().


I considered this, but is seems excessive to loop through the entire 
fb twice just to make a 4x6 cursor blink.




Yes, you're right about that.

Can you change tinydrm_xrgb_to_gray8 to match the other
copy/conversion functions so we can pass it a clip rectangle:

int tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr,
struct drm_framebuffer *fb,
struct drm_clip_rect *clip)

And move the import_attach part to the driver (repaper).
repaper doesn't do partial updates, so pass a full clip.


You should use this function to enable the regulator and init the
controller. Don't look at mi0283qt it should have been fixed.


ACK. But this is why I was not keen on writing a standalone driver. I 
know some things about kernel development, but not everything. How am 
I supposed to know what is OK to copy from other drivers and what is not? 


You can't know, and it's part of the review process to sort that out.
That being said, I really should have fixed mi0283qt, because it will
be copied...

And if I am going to be put down as the maintainer of this driver, it 
bothers me that I don't know so much about how it all works.




You don't need to know all the details. If I make a change, you can
assume that I know what I'm doing and ack it, but I need someone to
look at my patches, I can't apply my own patches without anyone looking
at it, we all make mistakes. And if someone else sends a patch and you
don't know if it is good or not, just ping me and I'll look at it.
Either way I have to look at all tinydrm patches before applying them.
I'm not keen on being default maintainer on drivers that I can't test.
The upside of being a maintainer is that you control the future of the
driver, what changes goes in.

And I'm kind of in the same boat as you, I know tinydrm, but drm is
very complex and I don't know half of what's going on. If I'm stuck or
out of my league, I have to ask for help. Like with adding drm formats.

Noralf.



Re: [PATCH v2 2/4] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-02 Thread David Lechner

On 08/02/2017 08:03 AM, Noralf Trønnes wrote:



Please use tinydrm_xrgb_to_gray8().


I considered this, but is seems excessive to loop through the entire fb 
twice just to make a 4x6 cursor blink.



You should use this function to enable the regulator and init the
controller. Don't look at mi0283qt it should have been fixed.


ACK. But this is why I was not keen on writing a standalone driver. I 
know some things about kernel development, but not everything. How am I 
supposed to know what is OK to copy from other drivers and what is not? 
And if I am going to be put down as the maintainer of this driver, it 
bothers me that I don't know so much about how it all works.




Why 2 emulation formats?
I chose DRM_FORMAT_XRGB since I expected everything to support it.
Please use only that.


Because my graphics library currently does not work with XRGB. ;-)

I can fix the graphics library and drop the RGB565 format in the kernel 
driver.





Re: [PATCH v2 2/4] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-02 Thread David Lechner

On 08/02/2017 08:03 AM, Noralf Trønnes wrote:



Please use tinydrm_xrgb_to_gray8().


I considered this, but is seems excessive to loop through the entire fb 
twice just to make a 4x6 cursor blink.



You should use this function to enable the regulator and init the
controller. Don't look at mi0283qt it should have been fixed.


ACK. But this is why I was not keen on writing a standalone driver. I 
know some things about kernel development, but not everything. How am I 
supposed to know what is OK to copy from other drivers and what is not? 
And if I am going to be put down as the maintainer of this driver, it 
bothers me that I don't know so much about how it all works.




Why 2 emulation formats?
I chose DRM_FORMAT_XRGB since I expected everything to support it.
Please use only that.


Because my graphics library currently does not work with XRGB. ;-)

I can fix the graphics library and drop the RGB565 format in the kernel 
driver.





Re: [PATCH v2 2/4] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-02 Thread Noralf Trønnes


Den 02.08.2017 00.11, skrev David Lechner:

LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
module for the ST7586 controller with parameters for the EV3 LCD display.

Signed-off-by: David Lechner 
---
  .../devicetree/bindings/display/st7586.txt |  26 +


I forgot, the binding doc should be a separate patch.

Noralf.


  drivers/gpu/drm/tinydrm/Kconfig|  10 +
  drivers/gpu/drm/tinydrm/Makefile   |   1 +
  drivers/gpu/drm/tinydrm/st7586.c   | 579 +
  include/drm/tinydrm/st7586.h   |  34 ++
  5 files changed, 650 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/display/st7586.txt
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c
  create mode 100644 include/drm/tinydrm/st7586.h

diff --git a/Documentation/devicetree/bindings/display/st7586.txt 
b/Documentation/devicetree/bindings/display/st7586.txt
new file mode 100644
index 000..acf784aa
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/st7586.txt
@@ -0,0 +1,26 @@
+Sitronix ST7586 display panel
+
+Required properties:
+- compatible:  "lego,ev3-lcd".
+
+The node for this driver must be a child node of a SPI controller, hence
+all mandatory properties described in ../spi/spi-bus.txt must be specified.
+
+Optional properties:
+- dc-gpios:D/C pin. The presence/absence of this GPIO determines
+   the panel interface mode (IM[3:0] pins):
+   - present: IM=x110 4-wire 8-bit data serial interface
+   - absent:  IM=x101 3-wire 9-bit data serial interface
+- reset-gpios: Reset pin
+- power-supply:A regulator node for the supply voltage.
+- backlight:   phandle of the backlight device attached to the panel
+- rotation:panel rotation in degrees counter clockwise (0,90,180,270)
+
+Example:
+   display@0{
+   compatible = "lego,ev3-lcd";
+   reg = <0>;
+   spi-max-frequency = <1000>;
+   dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
+   reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
+   };
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index f17c3ca..2e790e7 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -32,3 +32,13 @@ config TINYDRM_REPAPER
  2.71" TFT EPD Panel (E2271CS021)
  
  	  If M is selected the module will be called repaper.

+
+config TINYDRM_ST7586
+   tristate "DRM support for Sitronix ST7586 display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver for the following Sitronix ST7586 panels:
+ * LEGO MINDSTORMS EV3
+
+ If M is selected the module will be called st7586.
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 95bb4d4..0c184bd 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_TINYDRM_MIPI_DBI)  += mipi-dbi.o
  # Displays
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
+obj-$(CONFIG_TINYDRM_ST7586)   += st7586.o
diff --git a/drivers/gpu/drm/tinydrm/st7586.c b/drivers/gpu/drm/tinydrm/st7586.c
new file mode 100644
index 000..6093021
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,579 @@
+/*
+ * DRM driver for Sitronix ST7586 panels
+ *
+ * Copyright 2017 David Lechner 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+static inline u8 st7586_rgb565_to_gray2(u16 rgb)
+{
+   u8 r = (rgb & 0xf800) >> 11;
+   u8 g = (rgb & 0x07e0) >> 5;
+   u8 b = rgb & 0x001f;
+   /* ITU BT.601: Y = 0.299 R + 0.587 G + 0.114 B */
+   /* g is already * 2 because it is 6-bit */
+   u8 gray5 = (3 * r + 3 * g + b) / 10;
+
+   return gray5 >> 3;
+}
+
+static void st7586_from_rgb565(u8 *dst, void *vaddr,
+  struct drm_framebuffer *fb,
+  struct drm_clip_rect *clip)
+{
+   size_t len;
+   unsigned int x, y;
+   u16 *src, *buf;
+   u8 val;
+
+   /* 3 pixels per byte, so grow clip to nearest multiple of 3 */
+   clip->x1 = clip->x1 / 3 * 3;
+   clip->x2 = (clip->x2 + 2) / 3 * 3;
+   len = (clip->x2 - clip->x1) * sizeof(u16);
+
+   buf = kmalloc(len, GFP_KERNEL);
+   if (!buf)
+   return;
+
+   for (y = clip->y1; y < clip->y2; y++) {
+   src = vaddr + (y * fb->pitches[0]);
+   src += clip->x1;
+   

Re: [PATCH v2 2/4] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-02 Thread Noralf Trønnes


Den 02.08.2017 00.11, skrev David Lechner:

LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
module for the ST7586 controller with parameters for the EV3 LCD display.

Signed-off-by: David Lechner 
---
  .../devicetree/bindings/display/st7586.txt |  26 +


I forgot, the binding doc should be a separate patch.

Noralf.


  drivers/gpu/drm/tinydrm/Kconfig|  10 +
  drivers/gpu/drm/tinydrm/Makefile   |   1 +
  drivers/gpu/drm/tinydrm/st7586.c   | 579 +
  include/drm/tinydrm/st7586.h   |  34 ++
  5 files changed, 650 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/display/st7586.txt
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c
  create mode 100644 include/drm/tinydrm/st7586.h

diff --git a/Documentation/devicetree/bindings/display/st7586.txt 
b/Documentation/devicetree/bindings/display/st7586.txt
new file mode 100644
index 000..acf784aa
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/st7586.txt
@@ -0,0 +1,26 @@
+Sitronix ST7586 display panel
+
+Required properties:
+- compatible:  "lego,ev3-lcd".
+
+The node for this driver must be a child node of a SPI controller, hence
+all mandatory properties described in ../spi/spi-bus.txt must be specified.
+
+Optional properties:
+- dc-gpios:D/C pin. The presence/absence of this GPIO determines
+   the panel interface mode (IM[3:0] pins):
+   - present: IM=x110 4-wire 8-bit data serial interface
+   - absent:  IM=x101 3-wire 9-bit data serial interface
+- reset-gpios: Reset pin
+- power-supply:A regulator node for the supply voltage.
+- backlight:   phandle of the backlight device attached to the panel
+- rotation:panel rotation in degrees counter clockwise (0,90,180,270)
+
+Example:
+   display@0{
+   compatible = "lego,ev3-lcd";
+   reg = <0>;
+   spi-max-frequency = <1000>;
+   dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
+   reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
+   };
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index f17c3ca..2e790e7 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -32,3 +32,13 @@ config TINYDRM_REPAPER
  2.71" TFT EPD Panel (E2271CS021)
  
  	  If M is selected the module will be called repaper.

+
+config TINYDRM_ST7586
+   tristate "DRM support for Sitronix ST7586 display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver for the following Sitronix ST7586 panels:
+ * LEGO MINDSTORMS EV3
+
+ If M is selected the module will be called st7586.
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 95bb4d4..0c184bd 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_TINYDRM_MIPI_DBI)  += mipi-dbi.o
  # Displays
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
+obj-$(CONFIG_TINYDRM_ST7586)   += st7586.o
diff --git a/drivers/gpu/drm/tinydrm/st7586.c b/drivers/gpu/drm/tinydrm/st7586.c
new file mode 100644
index 000..6093021
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,579 @@
+/*
+ * DRM driver for Sitronix ST7586 panels
+ *
+ * Copyright 2017 David Lechner 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+static inline u8 st7586_rgb565_to_gray2(u16 rgb)
+{
+   u8 r = (rgb & 0xf800) >> 11;
+   u8 g = (rgb & 0x07e0) >> 5;
+   u8 b = rgb & 0x001f;
+   /* ITU BT.601: Y = 0.299 R + 0.587 G + 0.114 B */
+   /* g is already * 2 because it is 6-bit */
+   u8 gray5 = (3 * r + 3 * g + b) / 10;
+
+   return gray5 >> 3;
+}
+
+static void st7586_from_rgb565(u8 *dst, void *vaddr,
+  struct drm_framebuffer *fb,
+  struct drm_clip_rect *clip)
+{
+   size_t len;
+   unsigned int x, y;
+   u16 *src, *buf;
+   u8 val;
+
+   /* 3 pixels per byte, so grow clip to nearest multiple of 3 */
+   clip->x1 = clip->x1 / 3 * 3;
+   clip->x2 = (clip->x2 + 2) / 3 * 3;
+   len = (clip->x2 - clip->x1) * sizeof(u16);
+
+   buf = kmalloc(len, GFP_KERNEL);
+   if (!buf)
+   return;
+
+   for (y = clip->y1; y < clip->y2; y++) {
+   src = vaddr + (y * fb->pitches[0]);
+   src += clip->x1;
+   memcpy(buf, src, len);
+   src = buf;
+  

Re: [PATCH v2 2/4] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-02 Thread Noralf Trønnes


Den 02.08.2017 00.11, skrev David Lechner:

LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
module for the ST7586 controller with parameters for the EV3 LCD display.

Signed-off-by: David Lechner 
---
  .../devicetree/bindings/display/st7586.txt |  26 +
  drivers/gpu/drm/tinydrm/Kconfig|  10 +
  drivers/gpu/drm/tinydrm/Makefile   |   1 +
  drivers/gpu/drm/tinydrm/st7586.c   | 579 +
  include/drm/tinydrm/st7586.h   |  34 ++


Please add a MAINTAINERS entry.
That way you'll be notified on changes.


  5 files changed, 650 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/display/st7586.txt
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c
  create mode 100644 include/drm/tinydrm/st7586.h

diff --git a/Documentation/devicetree/bindings/display/st7586.txt 
b/Documentation/devicetree/bindings/display/st7586.txt
new file mode 100644
index 000..acf784aa
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/st7586.txt
@@ -0,0 +1,26 @@
+Sitronix ST7586 display panel
+
+Required properties:
+- compatible:  "lego,ev3-lcd".
+
+The node for this driver must be a child node of a SPI controller, hence
+all mandatory properties described in ../spi/spi-bus.txt must be specified.
+
+Optional properties:
+- dc-gpios:D/C pin. The presence/absence of this GPIO determines
+   the panel interface mode (IM[3:0] pins):
+   - present: IM=x110 4-wire 8-bit data serial interface
+   - absent:  IM=x101 3-wire 9-bit data serial interface


This doesn't match the ST7586 datasheet I have, the pins are called
IF[3:1] and the values are different.


+- reset-gpios: Reset pin
+- power-supply:A regulator node for the supply voltage.
+- backlight:   phandle of the backlight device attached to the panel
+- rotation:panel rotation in degrees counter clockwise (0,90,180,270)
+
+Example:
+   display@0{
+   compatible = "lego,ev3-lcd";
+   reg = <0>;
+   spi-max-frequency = <1000>;
+   dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
+   reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
+   };
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index f17c3ca..2e790e7 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -32,3 +32,13 @@ config TINYDRM_REPAPER
  2.71" TFT EPD Panel (E2271CS021)
  
  	  If M is selected the module will be called repaper.

+
+config TINYDRM_ST7586
+   tristate "DRM support for Sitronix ST7586 display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver for the following Sitronix ST7586 panels:
+ * LEGO MINDSTORMS EV3
+
+ If M is selected the module will be called st7586.
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 95bb4d4..0c184bd 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_TINYDRM_MIPI_DBI)  += mipi-dbi.o
  # Displays
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
+obj-$(CONFIG_TINYDRM_ST7586)   += st7586.o
diff --git a/drivers/gpu/drm/tinydrm/st7586.c b/drivers/gpu/drm/tinydrm/st7586.c
new file mode 100644
index 000..6093021
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,579 @@
+/*
+ * DRM driver for Sitronix ST7586 panels
+ *
+ * Copyright 2017 David Lechner 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+static inline u8 st7586_rgb565_to_gray2(u16 rgb)
+{
+   u8 r = (rgb & 0xf800) >> 11;
+   u8 g = (rgb & 0x07e0) >> 5;
+   u8 b = rgb & 0x001f;
+   /* ITU BT.601: Y = 0.299 R + 0.587 G + 0.114 B */
+   /* g is already * 2 because it is 6-bit */
+   u8 gray5 = (3 * r + 3 * g + b) / 10;
+
+   return gray5 >> 3;
+}
+
+static void st7586_from_rgb565(u8 *dst, void *vaddr,
+  struct drm_framebuffer *fb,
+  struct drm_clip_rect *clip)
+{
+   size_t len;
+   unsigned int x, y;
+   u16 *src, *buf;
+   u8 val;
+
+   /* 3 pixels per byte, so grow clip to nearest multiple of 3 */
+   clip->x1 = clip->x1 / 3 * 3;
+   clip->x2 = (clip->x2 + 2) / 3 * 3;
+   len = (clip->x2 - clip->x1) * sizeof(u16);
+
+   buf = kmalloc(len, GFP_KERNEL);
+   if (!buf)
+   return;
+
+   for (y = clip->y1; y < 

Re: [PATCH v2 2/4] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-02 Thread Noralf Trønnes


Den 02.08.2017 00.11, skrev David Lechner:

LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
module for the ST7586 controller with parameters for the EV3 LCD display.

Signed-off-by: David Lechner 
---
  .../devicetree/bindings/display/st7586.txt |  26 +
  drivers/gpu/drm/tinydrm/Kconfig|  10 +
  drivers/gpu/drm/tinydrm/Makefile   |   1 +
  drivers/gpu/drm/tinydrm/st7586.c   | 579 +
  include/drm/tinydrm/st7586.h   |  34 ++


Please add a MAINTAINERS entry.
That way you'll be notified on changes.


  5 files changed, 650 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/display/st7586.txt
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c
  create mode 100644 include/drm/tinydrm/st7586.h

diff --git a/Documentation/devicetree/bindings/display/st7586.txt 
b/Documentation/devicetree/bindings/display/st7586.txt
new file mode 100644
index 000..acf784aa
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/st7586.txt
@@ -0,0 +1,26 @@
+Sitronix ST7586 display panel
+
+Required properties:
+- compatible:  "lego,ev3-lcd".
+
+The node for this driver must be a child node of a SPI controller, hence
+all mandatory properties described in ../spi/spi-bus.txt must be specified.
+
+Optional properties:
+- dc-gpios:D/C pin. The presence/absence of this GPIO determines
+   the panel interface mode (IM[3:0] pins):
+   - present: IM=x110 4-wire 8-bit data serial interface
+   - absent:  IM=x101 3-wire 9-bit data serial interface


This doesn't match the ST7586 datasheet I have, the pins are called
IF[3:1] and the values are different.


+- reset-gpios: Reset pin
+- power-supply:A regulator node for the supply voltage.
+- backlight:   phandle of the backlight device attached to the panel
+- rotation:panel rotation in degrees counter clockwise (0,90,180,270)
+
+Example:
+   display@0{
+   compatible = "lego,ev3-lcd";
+   reg = <0>;
+   spi-max-frequency = <1000>;
+   dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
+   reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
+   };
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index f17c3ca..2e790e7 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -32,3 +32,13 @@ config TINYDRM_REPAPER
  2.71" TFT EPD Panel (E2271CS021)
  
  	  If M is selected the module will be called repaper.

+
+config TINYDRM_ST7586
+   tristate "DRM support for Sitronix ST7586 display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver for the following Sitronix ST7586 panels:
+ * LEGO MINDSTORMS EV3
+
+ If M is selected the module will be called st7586.
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 95bb4d4..0c184bd 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_TINYDRM_MIPI_DBI)  += mipi-dbi.o
  # Displays
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
+obj-$(CONFIG_TINYDRM_ST7586)   += st7586.o
diff --git a/drivers/gpu/drm/tinydrm/st7586.c b/drivers/gpu/drm/tinydrm/st7586.c
new file mode 100644
index 000..6093021
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,579 @@
+/*
+ * DRM driver for Sitronix ST7586 panels
+ *
+ * Copyright 2017 David Lechner 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+static inline u8 st7586_rgb565_to_gray2(u16 rgb)
+{
+   u8 r = (rgb & 0xf800) >> 11;
+   u8 g = (rgb & 0x07e0) >> 5;
+   u8 b = rgb & 0x001f;
+   /* ITU BT.601: Y = 0.299 R + 0.587 G + 0.114 B */
+   /* g is already * 2 because it is 6-bit */
+   u8 gray5 = (3 * r + 3 * g + b) / 10;
+
+   return gray5 >> 3;
+}
+
+static void st7586_from_rgb565(u8 *dst, void *vaddr,
+  struct drm_framebuffer *fb,
+  struct drm_clip_rect *clip)
+{
+   size_t len;
+   unsigned int x, y;
+   u16 *src, *buf;
+   u8 val;
+
+   /* 3 pixels per byte, so grow clip to nearest multiple of 3 */
+   clip->x1 = clip->x1 / 3 * 3;
+   clip->x2 = (clip->x2 + 2) / 3 * 3;
+   len = (clip->x2 - clip->x1) * sizeof(u16);
+
+   buf = kmalloc(len, GFP_KERNEL);
+   if (!buf)
+   return;
+
+   for (y = clip->y1; y < clip->y2; y++) {
+   src = vaddr + (y *