Re: [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-11 Thread Noralf Trønnes


Den 09.08.2017 19.59, skrev Noralf Trønnes:


Den 07.08.2017 19.39, 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 LEGO MINDSTORMS
EV3 LCD display.

Signed-off-by: David Lechner 
---


This looks good, even I understand the pixel packing now :-)
Now we wait for the DT maintainers to have their say.

Reviewed-by: Noralf Trønnes 



Thanks, applied to drm-misc together with dt binding.

Noralf.


v4 changes:
* correct order for MAINTAINERS entry
* Drop code not used by LEGO EV3 (regulator, backlight, suspend/resume)
* Make gpios required
* Use lookup table for pixel packing algorithm
* Don't modify clip when used as function parameter
* Use roundup/rounddown macros


  MAINTAINERS  |   6 +
  drivers/gpu/drm/tinydrm/Kconfig  |  10 +
  drivers/gpu/drm/tinydrm/Makefile |   1 +
  drivers/gpu/drm/tinydrm/st7586.c | 428 
+++

  4 files changed, 445 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a1e772e..19ca3e6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4380,6 +4380,12 @@ S:Orphan / Obsolete
  F:drivers/gpu/drm/sis/
  F:include/uapi/drm/sis_drm.h
  +DRM DRIVER FOR SITRONIX ST7586 PANELS
+M:David Lechner 
+S:Maintained
+F:drivers/gpu/drm/tinydrm/st7586.c
+F:Documentation/devicetree/bindings/display/st7586.txt
+
  DRM DRIVER FOR TDFX VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/tdfx/
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..1b39d3f
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,428 @@
+/*
+ * 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 
+
+/* controller-specific commands */
+#define ST7586_DISP_MODE_GRAY0x38
+#define ST7586_DISP_MODE_MONO0x39
+#define ST7586_ENABLE_DDRAM0x3a
+#define ST7586_SET_DISP_DUTY0xb0
+#define ST7586_SET_PART_DISP0xb4
+#define ST7586_SET_NLINE_INV0xb5
+#define ST7586_SET_VOP0xc0
+#define ST7586_SET_BIAS_SYSTEM0xc3
+#define ST7586_SET_BOOST_LEVEL0xc4
+#define ST7586_SET_VOP_OFFSET0xc7
+#define ST7586_ENABLE_ANALOG0xd0
+#define ST7586_AUTO_READ_CTRL0xd7
+#define ST7586_OTP_RW_CTRL0xe0
+#define ST7586_OTP_CTRL_OUT0xe1
+#define ST7586_OTP_READ0xe3
+
+#define ST7586_DISP_CTRL_MXBIT(6)
+#define ST7586_DISP_CTRL_MYBIT(7)
+
+/*
+ * The ST7586 controller has an unusual pixel format where 2bpp 
grayscale is
+ * packed 3 pixels per byte with the first two pixels using 3 bits 
and the 3rd

+ * pixel using only 2 bits.
+ *
+ * |  D7  |  D6  |  D5  ||  |  || 2bpp |
+ * | (D4) | (D3) | (D2) ||  D1  |  D0  || GRAY |
+ * +--+--+--++--+--++--+
+ * |  1   |  1   |  1   ||  1   |  1   || 0  0 | black
+ * |  1   |  0   |  0   ||  1   |  0   || 0  1 | dark gray
+ * |  0   |  1   |  0   ||  0   |  1   || 1  0 | light gray
+ * |  0   |  0   |  0   ||  0   |  0   || 1  1 | white
+ */
+
+static const u8 st7586_lookup[] = { 0x7, 0x4, 0x2, 0x0 };
+
+static void st7586_xrgb_to_gray332(u8 *dst, void *vaddr,
+   struct drm_framebuffer *fb,
+   struct drm_clip_rect *clip)
+{
+size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1);
+unsigned int x, y;
+u8 *src, *buf, 

Re: [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-11 Thread Noralf Trønnes


Den 09.08.2017 19.59, skrev Noralf Trønnes:


Den 07.08.2017 19.39, 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 LEGO MINDSTORMS
EV3 LCD display.

Signed-off-by: David Lechner 
---


This looks good, even I understand the pixel packing now :-)
Now we wait for the DT maintainers to have their say.

Reviewed-by: Noralf Trønnes 



Thanks, applied to drm-misc together with dt binding.

Noralf.


v4 changes:
* correct order for MAINTAINERS entry
* Drop code not used by LEGO EV3 (regulator, backlight, suspend/resume)
* Make gpios required
* Use lookup table for pixel packing algorithm
* Don't modify clip when used as function parameter
* Use roundup/rounddown macros


  MAINTAINERS  |   6 +
  drivers/gpu/drm/tinydrm/Kconfig  |  10 +
  drivers/gpu/drm/tinydrm/Makefile |   1 +
  drivers/gpu/drm/tinydrm/st7586.c | 428 
+++

  4 files changed, 445 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a1e772e..19ca3e6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4380,6 +4380,12 @@ S:Orphan / Obsolete
  F:drivers/gpu/drm/sis/
  F:include/uapi/drm/sis_drm.h
  +DRM DRIVER FOR SITRONIX ST7586 PANELS
+M:David Lechner 
+S:Maintained
+F:drivers/gpu/drm/tinydrm/st7586.c
+F:Documentation/devicetree/bindings/display/st7586.txt
+
  DRM DRIVER FOR TDFX VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/tdfx/
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..1b39d3f
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,428 @@
+/*
+ * 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 
+
+/* controller-specific commands */
+#define ST7586_DISP_MODE_GRAY0x38
+#define ST7586_DISP_MODE_MONO0x39
+#define ST7586_ENABLE_DDRAM0x3a
+#define ST7586_SET_DISP_DUTY0xb0
+#define ST7586_SET_PART_DISP0xb4
+#define ST7586_SET_NLINE_INV0xb5
+#define ST7586_SET_VOP0xc0
+#define ST7586_SET_BIAS_SYSTEM0xc3
+#define ST7586_SET_BOOST_LEVEL0xc4
+#define ST7586_SET_VOP_OFFSET0xc7
+#define ST7586_ENABLE_ANALOG0xd0
+#define ST7586_AUTO_READ_CTRL0xd7
+#define ST7586_OTP_RW_CTRL0xe0
+#define ST7586_OTP_CTRL_OUT0xe1
+#define ST7586_OTP_READ0xe3
+
+#define ST7586_DISP_CTRL_MXBIT(6)
+#define ST7586_DISP_CTRL_MYBIT(7)
+
+/*
+ * The ST7586 controller has an unusual pixel format where 2bpp 
grayscale is
+ * packed 3 pixels per byte with the first two pixels using 3 bits 
and the 3rd

+ * pixel using only 2 bits.
+ *
+ * |  D7  |  D6  |  D5  ||  |  || 2bpp |
+ * | (D4) | (D3) | (D2) ||  D1  |  D0  || GRAY |
+ * +--+--+--++--+--++--+
+ * |  1   |  1   |  1   ||  1   |  1   || 0  0 | black
+ * |  1   |  0   |  0   ||  1   |  0   || 0  1 | dark gray
+ * |  0   |  1   |  0   ||  0   |  1   || 1  0 | light gray
+ * |  0   |  0   |  0   ||  0   |  0   || 1  1 | white
+ */
+
+static const u8 st7586_lookup[] = { 0x7, 0x4, 0x2, 0x0 };
+
+static void st7586_xrgb_to_gray332(u8 *dst, void *vaddr,
+   struct drm_framebuffer *fb,
+   struct drm_clip_rect *clip)
+{
+size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1);
+unsigned int x, y;
+u8 *src, *buf, val;
+
+buf = kmalloc(len, GFP_KERNEL);
+if (!buf)
+return;
+
+

Re: [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-09 Thread Noralf Trønnes


Den 07.08.2017 19.39, 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 LEGO MINDSTORMS
EV3 LCD display.

Signed-off-by: David Lechner 
---


This looks good, even I understand the pixel packing now :-)
Now we wait for the DT maintainers to have their say.

Reviewed-by: Noralf Trønnes 


v4 changes:
* correct order for MAINTAINERS entry
* Drop code not used by LEGO EV3 (regulator, backlight, suspend/resume)
* Make gpios required
* Use lookup table for pixel packing algorithm
* Don't modify clip when used as function parameter
* Use roundup/rounddown macros


  MAINTAINERS  |   6 +
  drivers/gpu/drm/tinydrm/Kconfig  |  10 +
  drivers/gpu/drm/tinydrm/Makefile |   1 +
  drivers/gpu/drm/tinydrm/st7586.c | 428 +++
  4 files changed, 445 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a1e772e..19ca3e6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4380,6 +4380,12 @@ S:   Orphan / Obsolete
  F:drivers/gpu/drm/sis/
  F:include/uapi/drm/sis_drm.h
  
+DRM DRIVER FOR SITRONIX ST7586 PANELS

+M: David Lechner 
+S: Maintained
+F: drivers/gpu/drm/tinydrm/st7586.c
+F: Documentation/devicetree/bindings/display/st7586.txt
+
  DRM DRIVER FOR TDFX VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/tdfx/
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..1b39d3f
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,428 @@
+/*
+ * 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 
+
+/* controller-specific commands */
+#define ST7586_DISP_MODE_GRAY  0x38
+#define ST7586_DISP_MODE_MONO  0x39
+#define ST7586_ENABLE_DDRAM0x3a
+#define ST7586_SET_DISP_DUTY   0xb0
+#define ST7586_SET_PART_DISP   0xb4
+#define ST7586_SET_NLINE_INV   0xb5
+#define ST7586_SET_VOP 0xc0
+#define ST7586_SET_BIAS_SYSTEM 0xc3
+#define ST7586_SET_BOOST_LEVEL 0xc4
+#define ST7586_SET_VOP_OFFSET  0xc7
+#define ST7586_ENABLE_ANALOG   0xd0
+#define ST7586_AUTO_READ_CTRL  0xd7
+#define ST7586_OTP_RW_CTRL 0xe0
+#define ST7586_OTP_CTRL_OUT0xe1
+#define ST7586_OTP_READ0xe3
+
+#define ST7586_DISP_CTRL_MXBIT(6)
+#define ST7586_DISP_CTRL_MYBIT(7)
+
+/*
+ * The ST7586 controller has an unusual pixel format where 2bpp grayscale is
+ * packed 3 pixels per byte with the first two pixels using 3 bits and the 3rd
+ * pixel using only 2 bits.
+ *
+ * |  D7  |  D6  |  D5  ||  |  || 2bpp |
+ * | (D4) | (D3) | (D2) ||  D1  |  D0  || GRAY |
+ * +--+--+--++--+--++--+
+ * |  1   |  1   |  1   ||  1   |  1   || 0  0 | black
+ * |  1   |  0   |  0   ||  1   |  0   || 0  1 | dark gray
+ * |  0   |  1   |  0   ||  0   |  1   || 1  0 | light gray
+ * |  0   |  0   |  0   ||  0   |  0   || 1  1 | white
+ */
+
+static const u8 st7586_lookup[] = { 0x7, 0x4, 0x2, 0x0 };
+
+static void st7586_xrgb_to_gray332(u8 *dst, void *vaddr,
+  struct drm_framebuffer *fb,
+  struct drm_clip_rect *clip)
+{
+   size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1);
+   unsigned int x, y;
+   u8 *src, *buf, val;
+
+   buf = kmalloc(len, GFP_KERNEL);

Re: [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-09 Thread Noralf Trønnes


Den 07.08.2017 19.39, 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 LEGO MINDSTORMS
EV3 LCD display.

Signed-off-by: David Lechner 
---


This looks good, even I understand the pixel packing now :-)
Now we wait for the DT maintainers to have their say.

Reviewed-by: Noralf Trønnes 


v4 changes:
* correct order for MAINTAINERS entry
* Drop code not used by LEGO EV3 (regulator, backlight, suspend/resume)
* Make gpios required
* Use lookup table for pixel packing algorithm
* Don't modify clip when used as function parameter
* Use roundup/rounddown macros


  MAINTAINERS  |   6 +
  drivers/gpu/drm/tinydrm/Kconfig  |  10 +
  drivers/gpu/drm/tinydrm/Makefile |   1 +
  drivers/gpu/drm/tinydrm/st7586.c | 428 +++
  4 files changed, 445 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a1e772e..19ca3e6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4380,6 +4380,12 @@ S:   Orphan / Obsolete
  F:drivers/gpu/drm/sis/
  F:include/uapi/drm/sis_drm.h
  
+DRM DRIVER FOR SITRONIX ST7586 PANELS

+M: David Lechner 
+S: Maintained
+F: drivers/gpu/drm/tinydrm/st7586.c
+F: Documentation/devicetree/bindings/display/st7586.txt
+
  DRM DRIVER FOR TDFX VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/tdfx/
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..1b39d3f
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,428 @@
+/*
+ * 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 
+
+/* controller-specific commands */
+#define ST7586_DISP_MODE_GRAY  0x38
+#define ST7586_DISP_MODE_MONO  0x39
+#define ST7586_ENABLE_DDRAM0x3a
+#define ST7586_SET_DISP_DUTY   0xb0
+#define ST7586_SET_PART_DISP   0xb4
+#define ST7586_SET_NLINE_INV   0xb5
+#define ST7586_SET_VOP 0xc0
+#define ST7586_SET_BIAS_SYSTEM 0xc3
+#define ST7586_SET_BOOST_LEVEL 0xc4
+#define ST7586_SET_VOP_OFFSET  0xc7
+#define ST7586_ENABLE_ANALOG   0xd0
+#define ST7586_AUTO_READ_CTRL  0xd7
+#define ST7586_OTP_RW_CTRL 0xe0
+#define ST7586_OTP_CTRL_OUT0xe1
+#define ST7586_OTP_READ0xe3
+
+#define ST7586_DISP_CTRL_MXBIT(6)
+#define ST7586_DISP_CTRL_MYBIT(7)
+
+/*
+ * The ST7586 controller has an unusual pixel format where 2bpp grayscale is
+ * packed 3 pixels per byte with the first two pixels using 3 bits and the 3rd
+ * pixel using only 2 bits.
+ *
+ * |  D7  |  D6  |  D5  ||  |  || 2bpp |
+ * | (D4) | (D3) | (D2) ||  D1  |  D0  || GRAY |
+ * +--+--+--++--+--++--+
+ * |  1   |  1   |  1   ||  1   |  1   || 0  0 | black
+ * |  1   |  0   |  0   ||  1   |  0   || 0  1 | dark gray
+ * |  0   |  1   |  0   ||  0   |  1   || 1  0 | light gray
+ * |  0   |  0   |  0   ||  0   |  0   || 1  1 | white
+ */
+
+static const u8 st7586_lookup[] = { 0x7, 0x4, 0x2, 0x0 };
+
+static void st7586_xrgb_to_gray332(u8 *dst, void *vaddr,
+  struct drm_framebuffer *fb,
+  struct drm_clip_rect *clip)
+{
+   size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1);
+   unsigned int x, y;
+   u8 *src, *buf, val;
+
+   buf = kmalloc(len, GFP_KERNEL);
+   if (!buf)
+   return;
+
+   tinydrm_xrgb_to_gray8(buf,