Re: [PATCH 2/6] drm/panel: Add driver for BOE TH101MB31IG002-28A panel

2023-12-26 Thread Jessica Zhang




On 12/22/2023 3:05 AM, Manuel Traut wrote:

From: Segfault 

The BOE TH101MB31IG002-28A panel is a WXGA panel.
It is used in Pine64 Pinetab2 and PinetabV.

Signed-off-by: Segfault 
Signed-off-by: Manuel Traut 
---
  drivers/gpu/drm/panel/Kconfig  |  11 +
  drivers/gpu/drm/panel/Makefile |   1 +
  .../gpu/drm/panel/panel-boe-th101mb31ig002-28a.c   | 307 +
  3 files changed, 319 insertions(+)

diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
index 99e14dc212ec..927ddd10e688 100644
--- a/drivers/gpu/drm/panel/Kconfig
+++ b/drivers/gpu/drm/panel/Kconfig
@@ -67,6 +67,17 @@ config DRM_PANEL_BOE_HIMAX8279D
  24 bit RGB per pixel. It provides a MIPI DSI interface to
  the host and has a built-in LED backlight.
  
+config DRM_PANEL_BOE_TH101MB31UIG002_28A

+   tristate "Boe TH101MB31UIG002-28A panel"
+   depends on OF
+   depends on DRM_MIPI_DSI
+   depends on BACKLIGHT_CLASS_DEVICE
+   help
+ Say Y here if you want to enable support for Boe
+ TH101MB31UIG002-28A TFT-LCD modules. The panel has a 800x1280
+ resolution and uses 24 bit RGB per pixel. It provides a MIPI DSI
+ interface to the host and has a built-in LED backlight.
+
  config DRM_PANEL_BOE_TV101WUM_NL6
tristate "BOE TV101WUM and AUO KD101N80 45NA 1200x1920 panel"
depends on OF
diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
index d10c3de51c6d..dd6e1ac9d0a2 100644
--- a/drivers/gpu/drm/panel/Makefile
+++ b/drivers/gpu/drm/panel/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_PANEL_ASUS_Z00T_TM5P5_NT35596) += 
panel-asus-z00t-tm5p5-n35596.
  obj-$(CONFIG_DRM_PANEL_AUO_A030JTN01) += panel-auo-a030jtn01.o
  obj-$(CONFIG_DRM_PANEL_BOE_BF060Y8M_AJ0) += panel-boe-bf060y8m-aj0.o
  obj-$(CONFIG_DRM_PANEL_BOE_HIMAX8279D) += panel-boe-himax8279d.o
+obj-$(CONFIG_DRM_PANEL_BOE_TH101MB31UIG002_28A) += 
panel-boe-th101mb31ig002-28a.o
  obj-$(CONFIG_DRM_PANEL_BOE_TV101WUM_NL6) += panel-boe-tv101wum-nl6.o
  obj-$(CONFIG_DRM_PANEL_DSI_CM) += panel-dsi-cm.o
  obj-$(CONFIG_DRM_PANEL_LVDS) += panel-lvds.o
diff --git a/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c 
b/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c
new file mode 100644
index ..ac1dc99a0300
--- /dev/null
+++ b/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c
@@ -0,0 +1,307 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2023 Alexander Warnecke 
+ * Copyright (c) 2023 Manuel Traut 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+struct boe_th101mb31ig002 {
+   struct drm_panel panel;
+   bool enabled;
+   bool prepared;


Hi Manuel,

If I remember correctly, commit 
d2aacaf07395bd798373cbec6af05fff4147aff3 should have introduced 
prepared/enabled do the drm_panel struct.


Thanks,

Jessica Zhang


+
+   struct mipi_dsi_device *dsi;
+
+   struct regulator *power;
+   struct gpio_desc *enable;
+   struct gpio_desc *reset;
+
+   enum drm_panel_orientation orientation;
+};
+
+static int boe_th101mb31ig002_disable(struct drm_panel *panel)
+{
+   struct boe_th101mb31ig002 *ctx = container_of(panel,
+ struct boe_th101mb31ig002,
+ panel);
+
+   if (!ctx->enabled)
+   return 0;
+
+   mipi_dsi_dcs_set_display_off(ctx->dsi);
+   msleep(120);
+   ctx->enabled = false;
+
+   return 0;
+}
+
+static int boe_th101mb31ig002_unprepare(struct drm_panel *panel)
+{
+   struct boe_th101mb31ig002 *ctx = container_of(panel,
+ struct boe_th101mb31ig002,
+ panel);
+
+   if (!ctx->prepared)
+   return 0;
+
+   mipi_dsi_dcs_enter_sleep_mode(ctx->dsi);
+   msleep(220);
+   gpiod_set_value_cansleep(ctx->reset, 1);
+   gpiod_set_value_cansleep(ctx->enable, 0);
+   regulator_disable(ctx->power);
+   ctx->prepared = false;
+
+   return 0;
+}
+
+static int boe_th101mb31ig002_prepare(struct drm_panel *panel)
+{
+   struct boe_th101mb31ig002 *ctx = container_of(panel,
+ struct boe_th101mb31ig002,
+ panel);
+   struct mipi_dsi_device *dsi = ctx->dsi;
+   int ret;
+
+   if (ctx->prepared)
+   return 0;
+
+   ret = regulator_enable(ctx->power);
+   if (ret) {
+   dev_err(>dev, "Failed to enable power supply: %d\n", ret);
+   return ret;
+   }
+
+   gpiod_set_value_cansleep(ctx->enable, 1);
+   msleep(120);
+   gpiod_direction_output(ctx->reset, 1);
+   msleep(120);
+   gpiod_direction_output(ctx->reset, 0);
+   msleep(120);
+
+

Re: [PATCH 2/6] drm/panel: Add driver for BOE TH101MB31IG002-28A panel

2023-12-22 Thread Fabio Estevam
On Fri, Dec 22, 2023 at 2:32 PM Manuel Traut  wrote:
>
> From: Segfault 
>
> The BOE TH101MB31IG002-28A panel is a WXGA panel.
> It is used in Pine64 Pinetab2 and PinetabV.
>
> Signed-off-by: Segfault 

Please use a real name instead...

> +MODULE_AUTHOR("Alexander Warnecke ");

like here.


[PATCH 2/6] drm/panel: Add driver for BOE TH101MB31IG002-28A panel

2023-12-22 Thread Manuel Traut
From: Segfault 

The BOE TH101MB31IG002-28A panel is a WXGA panel.
It is used in Pine64 Pinetab2 and PinetabV.

Signed-off-by: Segfault 
Signed-off-by: Manuel Traut 
---
 drivers/gpu/drm/panel/Kconfig  |  11 +
 drivers/gpu/drm/panel/Makefile |   1 +
 .../gpu/drm/panel/panel-boe-th101mb31ig002-28a.c   | 307 +
 3 files changed, 319 insertions(+)

diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
index 99e14dc212ec..927ddd10e688 100644
--- a/drivers/gpu/drm/panel/Kconfig
+++ b/drivers/gpu/drm/panel/Kconfig
@@ -67,6 +67,17 @@ config DRM_PANEL_BOE_HIMAX8279D
  24 bit RGB per pixel. It provides a MIPI DSI interface to
  the host and has a built-in LED backlight.
 
+config DRM_PANEL_BOE_TH101MB31UIG002_28A
+   tristate "Boe TH101MB31UIG002-28A panel"
+   depends on OF
+   depends on DRM_MIPI_DSI
+   depends on BACKLIGHT_CLASS_DEVICE
+   help
+ Say Y here if you want to enable support for Boe
+ TH101MB31UIG002-28A TFT-LCD modules. The panel has a 800x1280
+ resolution and uses 24 bit RGB per pixel. It provides a MIPI DSI
+ interface to the host and has a built-in LED backlight.
+
 config DRM_PANEL_BOE_TV101WUM_NL6
tristate "BOE TV101WUM and AUO KD101N80 45NA 1200x1920 panel"
depends on OF
diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
index d10c3de51c6d..dd6e1ac9d0a2 100644
--- a/drivers/gpu/drm/panel/Makefile
+++ b/drivers/gpu/drm/panel/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_PANEL_ASUS_Z00T_TM5P5_NT35596) += 
panel-asus-z00t-tm5p5-n35596.
 obj-$(CONFIG_DRM_PANEL_AUO_A030JTN01) += panel-auo-a030jtn01.o
 obj-$(CONFIG_DRM_PANEL_BOE_BF060Y8M_AJ0) += panel-boe-bf060y8m-aj0.o
 obj-$(CONFIG_DRM_PANEL_BOE_HIMAX8279D) += panel-boe-himax8279d.o
+obj-$(CONFIG_DRM_PANEL_BOE_TH101MB31UIG002_28A) += 
panel-boe-th101mb31ig002-28a.o
 obj-$(CONFIG_DRM_PANEL_BOE_TV101WUM_NL6) += panel-boe-tv101wum-nl6.o
 obj-$(CONFIG_DRM_PANEL_DSI_CM) += panel-dsi-cm.o
 obj-$(CONFIG_DRM_PANEL_LVDS) += panel-lvds.o
diff --git a/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c 
b/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c
new file mode 100644
index ..ac1dc99a0300
--- /dev/null
+++ b/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c
@@ -0,0 +1,307 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2023 Alexander Warnecke 
+ * Copyright (c) 2023 Manuel Traut 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+struct boe_th101mb31ig002 {
+   struct drm_panel panel;
+   bool enabled;
+   bool prepared;
+
+   struct mipi_dsi_device *dsi;
+
+   struct regulator *power;
+   struct gpio_desc *enable;
+   struct gpio_desc *reset;
+
+   enum drm_panel_orientation orientation;
+};
+
+static int boe_th101mb31ig002_disable(struct drm_panel *panel)
+{
+   struct boe_th101mb31ig002 *ctx = container_of(panel,
+ struct boe_th101mb31ig002,
+ panel);
+
+   if (!ctx->enabled)
+   return 0;
+
+   mipi_dsi_dcs_set_display_off(ctx->dsi);
+   msleep(120);
+   ctx->enabled = false;
+
+   return 0;
+}
+
+static int boe_th101mb31ig002_unprepare(struct drm_panel *panel)
+{
+   struct boe_th101mb31ig002 *ctx = container_of(panel,
+ struct boe_th101mb31ig002,
+ panel);
+
+   if (!ctx->prepared)
+   return 0;
+
+   mipi_dsi_dcs_enter_sleep_mode(ctx->dsi);
+   msleep(220);
+   gpiod_set_value_cansleep(ctx->reset, 1);
+   gpiod_set_value_cansleep(ctx->enable, 0);
+   regulator_disable(ctx->power);
+   ctx->prepared = false;
+
+   return 0;
+}
+
+static int boe_th101mb31ig002_prepare(struct drm_panel *panel)
+{
+   struct boe_th101mb31ig002 *ctx = container_of(panel,
+ struct boe_th101mb31ig002,
+ panel);
+   struct mipi_dsi_device *dsi = ctx->dsi;
+   int ret;
+
+   if (ctx->prepared)
+   return 0;
+
+   ret = regulator_enable(ctx->power);
+   if (ret) {
+   dev_err(>dev, "Failed to enable power supply: %d\n", ret);
+   return ret;
+   }
+
+   gpiod_set_value_cansleep(ctx->enable, 1);
+   msleep(120);
+   gpiod_direction_output(ctx->reset, 1);
+   msleep(120);
+   gpiod_direction_output(ctx->reset, 0);
+   msleep(120);
+
+   mipi_dsi_dcs_write_seq(dsi, 0xE0, 0xAB, 0xBA);
+   mipi_dsi_dcs_write_seq(dsi, 0xE1, 0xBA, 0xAB);
+   mipi_dsi_dcs_write_seq(dsi, 0xB1, 0x10, 0x01, 0x47, 0xFF);
+   mipi_dsi_dcs_write_seq(dsi, 0xB2, 0x0C, 0x14, 0x04, 0x50,