352 lines
11 KiB
Diff
352 lines
11 KiB
Diff
From a5da017fee5cea7a0d1cb5394996aaad5a53a341 Mon Sep 17 00:00:00 2001
|
|
From: Segfault <awarnecke002@hotmail.com>
|
|
Date: Fri, 20 Jan 2023 14:20:27 +1100
|
|
Subject: [PATCH 396/464] drm/panel: add BOE TH101MB31IG002-28A driver
|
|
|
|
This driver is used for the panel in the Pine64 PineTab2.
|
|
|
|
Signed-off-by: Segfault <awarnecke002@hotmail.com>
|
|
---
|
|
drivers/gpu/drm/panel/Kconfig | 11 +
|
|
drivers/gpu/drm/panel/Makefile | 1 +
|
|
.../drm/panel/panel-boe-th101mb31ig002-28a.c | 293 ++++++++++++++++++
|
|
3 files changed, 305 insertions(+)
|
|
create mode 100644 drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c
|
|
|
|
diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
|
|
index 203c0ef0bbfd..81b9301b08f8 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 30cf553c8d1d..049d133d4b21 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 000000000000..2879d6b7aa8a
|
|
--- /dev/null
|
|
+++ b/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c
|
|
@@ -0,0 +1,293 @@
|
|
+// SPDX-License-Identifier: GPL-2.0-only
|
|
+/*
|
|
+ * Copyright (c) 2023 Alexander Warnecke <awarnecke002@hotmail.com>
|
|
+ */
|
|
+
|
|
+#include <linux/delay.h>
|
|
+#include <linux/gpio/consumer.h>
|
|
+#include <linux/module.h>
|
|
+#include <linux/of.h>
|
|
+#include <linux/of_device.h>
|
|
+#include <linux/regulator/consumer.h>
|
|
+
|
|
+#include <drm/drm_connector.h>
|
|
+#include <drm/drm_mipi_dsi.h>
|
|
+#include <drm/drm_modes.h>
|
|
+#include <drm/drm_panel.h>
|
|
+
|
|
+struct boe {
|
|
+ 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 inline struct boe *panel_to_boe(struct drm_panel *panel)
|
|
+{
|
|
+ return container_of(panel, struct boe, panel);
|
|
+}
|
|
+
|
|
+static int boe_disable(struct drm_panel *panel)
|
|
+{
|
|
+ struct boe *ctx = panel_to_boe(panel);
|
|
+
|
|
+ if (!ctx->enabled)
|
|
+ return 0;
|
|
+
|
|
+ mipi_dsi_dcs_set_display_off(ctx->dsi);
|
|
+
|
|
+ msleep(120);
|
|
+
|
|
+ ctx->enabled = false;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int boe_unprepare(struct drm_panel *panel)
|
|
+{
|
|
+ struct boe *ctx = panel_to_boe(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_prepare(struct drm_panel *panel)
|
|
+{
|
|
+ struct boe *ctx = panel_to_boe(panel);
|
|
+ struct mipi_dsi_device *dsi = ctx->dsi;
|
|
+ int ret;
|
|
+
|
|
+ if (ctx->prepared)
|
|
+ return 0;
|
|
+
|
|
+ ret = regulator_enable(ctx->power);
|
|
+ if (ret) {
|
|
+ dev_err(&dsi->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_buffer(dsi, (u8[]){ 0xE0, 0xAB, 0xBA }, 3);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xE1, 0xBA, 0xAB }, 3);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xB1, 0x10, 0x01, 0x47, 0xFF }, 5);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xB2, 0x0C, 0x14, 0x04, 0x50, 0x50, 0x14 }, 7);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xB3, 0x56, 0x53, 0x00 }, 4);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xB4, 0x33, 0x30, 0x04 }, 4);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xB6, 0xB0, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00 }, 8);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xB8, 0x05, 0x12, 0x29, 0x49, 0x48, 0x00, 0x00 }, 8);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xB9, 0x7C, 0x65, 0x55, 0x49, 0x46, 0x36, 0x3B, 0x24, 0x3D, 0x3C, 0x3D, 0x5C, 0x4C, 0x55, 0x47, 0x46, 0x39, 0x26, 0x06, 0x7C, 0x65, 0x55, 0x49, 0x46, 0x36, 0x3B, 0x24, 0x3D, 0x3C, 0x3D, 0x5C, 0x4C, 0x55, 0x47, 0x46, 0x39, 0x26, 0x06 }, 39);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xC0, 0xFF, 0x87, 0x12, 0x34, 0x44, 0x44, 0x44, 0x44, 0x98, 0x04, 0x98, 0x04, 0x0F, 0x00, 0x00, 0xC1 }, 17);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xC1, 0x54, 0x94, 0x02, 0x85, 0x9F, 0x00, 0x7F, 0x00, 0x54, 0x00 }, 11);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xC2, 0x17, 0x09, 0x08, 0x89, 0x08, 0x11, 0x22, 0x20, 0x44, 0xFF, 0x18, 0x00 }, 13);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xC3, 0x86, 0x46, 0x05, 0x05, 0x1C, 0x1C, 0x1D, 0x1D, 0x02, 0x1F, 0x1F, 0x1E, 0x1E, 0x0F, 0x0F, 0x0D, 0x0D, 0x13, 0x13, 0x11, 0x11, 0x00 }, 23);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xC4, 0x07, 0x07, 0x04, 0x04, 0x1C, 0x1C, 0x1D, 0x1D, 0x02, 0x1F, 0x1F, 0x1E, 0x1E, 0x0E, 0x0E, 0x0C, 0x0C, 0x12, 0x12, 0x10, 0x10, 0x00 }, 23);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xC6, 0x2A, 0x2A }, 3);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xC8, 0x21, 0x00, 0x31, 0x42, 0x34, 0x16 }, 7);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xCA, 0xCB, 0x43 }, 3);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xCD, 0x0E, 0x4B, 0x4B, 0x20, 0x19, 0x6B, 0x06, 0xB3 }, 9);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xD2, 0xE3, 0x2B, 0x38, 0x00 }, 5);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xD4, 0x00, 0x01, 0x00, 0x0E, 0x04, 0x44, 0x08, 0x10, 0x00, 0x00, 0x00 }, 12);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xE6, 0x80, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, 9);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xF0, 0x12, 0x03, 0x20, 0x00, 0xFF }, 6);
|
|
+ mipi_dsi_dcs_write_buffer(dsi, (u8[]){ 0xF3, 0x00 }, 2);
|
|
+
|
|
+ mipi_dsi_dcs_exit_sleep_mode(dsi);
|
|
+
|
|
+ msleep(120);
|
|
+
|
|
+ ctx->prepared = true;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int boe_enable(struct drm_panel *panel)
|
|
+{
|
|
+ struct boe *ctx = panel_to_boe(panel);
|
|
+
|
|
+ if (ctx->enabled)
|
|
+ return 0;
|
|
+
|
|
+ mipi_dsi_dcs_set_display_on(ctx->dsi);
|
|
+
|
|
+ msleep(120);
|
|
+
|
|
+ ctx->enabled = true;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static const struct drm_display_mode boe_default_mode = {
|
|
+ .clock = 73500,
|
|
+
|
|
+ .hdisplay = 800,
|
|
+ .hsync_start = 800 + 64,
|
|
+ .hsync_end = 800 + 64 + 16,
|
|
+ .htotal = 800 + 64 + 16 + 64,
|
|
+
|
|
+ .vdisplay = 1280,
|
|
+ .vsync_start = 1280 + 2,
|
|
+ .vsync_end = 1280 + 2 + 4,
|
|
+ .vtotal = 1280 + 2 + 4 + 12,
|
|
+
|
|
+ .type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
|
|
+};
|
|
+
|
|
+static int boe_get_modes(struct drm_panel *panel,
|
|
+ struct drm_connector *connector)
|
|
+{
|
|
+ struct boe *ctx = panel_to_boe(panel);
|
|
+ struct drm_display_mode *mode;
|
|
+
|
|
+ mode = drm_mode_duplicate(connector->dev, &boe_default_mode);
|
|
+ if (!mode) {
|
|
+ dev_err(panel->dev, "Failed to add mode %ux%u@%u\n",
|
|
+ boe_default_mode.hdisplay,
|
|
+ boe_default_mode.vdisplay,
|
|
+ drm_mode_vrefresh(&boe_default_mode));
|
|
+ return -ENOMEM;
|
|
+ }
|
|
+
|
|
+ drm_mode_set_name(mode);
|
|
+ drm_mode_probed_add(connector, mode);
|
|
+
|
|
+ connector->display_info.bpc = 8;
|
|
+ connector->display_info.width_mm = 216;
|
|
+ connector->display_info.height_mm = 135;
|
|
+
|
|
+ /*
|
|
+ * TODO: Remove once all drm drivers call
|
|
+ * drm_connector_set_orientation_from_panel()
|
|
+ */
|
|
+ drm_connector_set_panel_orientation(connector, ctx->orientation);
|
|
+
|
|
+ return 1;
|
|
+}
|
|
+
|
|
+static enum drm_panel_orientation boe_get_orientation(struct drm_panel *panel)
|
|
+{
|
|
+ struct boe *ctx = panel_to_boe(panel);
|
|
+
|
|
+ return ctx->orientation;
|
|
+}
|
|
+
|
|
+static const struct drm_panel_funcs boe_funcs = {
|
|
+ .disable = boe_disable,
|
|
+ .unprepare = boe_unprepare,
|
|
+ .prepare = boe_prepare,
|
|
+ .enable = boe_enable,
|
|
+ .get_modes = boe_get_modes,
|
|
+ .get_orientation = boe_get_orientation,
|
|
+};
|
|
+
|
|
+static int boe_dsi_probe(struct mipi_dsi_device *dsi)
|
|
+{
|
|
+ struct boe *ctx;
|
|
+ int ret;
|
|
+
|
|
+ ctx = devm_kzalloc(&dsi->dev, sizeof(*ctx), GFP_KERNEL);
|
|
+ if (!ctx)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ ctx->enabled = false;
|
|
+ ctx->prepared = false;
|
|
+
|
|
+ mipi_dsi_set_drvdata(dsi, ctx);
|
|
+ ctx->dsi = dsi;
|
|
+
|
|
+ drm_panel_init(&ctx->panel, &dsi->dev, &boe_funcs,
|
|
+ DRM_MODE_CONNECTOR_DSI);
|
|
+
|
|
+ ctx->power = devm_regulator_get(&dsi->dev, "power");
|
|
+ if (IS_ERR(ctx->power))
|
|
+ return dev_err_probe(&dsi->dev, PTR_ERR(ctx->power),
|
|
+ "Failed to get power regulator\n");
|
|
+
|
|
+ ctx->enable = devm_gpiod_get(&dsi->dev, "enable", GPIOD_OUT_LOW);
|
|
+ if (IS_ERR(ctx->enable))
|
|
+ return dev_err_probe(&dsi->dev, PTR_ERR(ctx->enable),
|
|
+ "Failed to get enable GPIO\n");
|
|
+
|
|
+ ctx->reset = devm_gpiod_get(&dsi->dev, "reset", GPIOD_OUT_HIGH);
|
|
+ if (IS_ERR(ctx->reset))
|
|
+ return dev_err_probe(&dsi->dev, PTR_ERR(ctx->reset),
|
|
+ "Failed to get reset GPIO\n");
|
|
+
|
|
+ ret = of_drm_get_panel_orientation(dsi->dev.of_node, &ctx->orientation);
|
|
+ if (ret)
|
|
+ return dev_err_probe(&dsi->dev, ret,
|
|
+ "Failed to get orientation\n");
|
|
+
|
|
+ ret = drm_panel_of_backlight(&ctx->panel);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ drm_panel_add(&ctx->panel);
|
|
+
|
|
+ dsi->lanes = 4;
|
|
+ dsi->format = MIPI_DSI_FMT_RGB888;
|
|
+ dsi->mode_flags = MIPI_DSI_MODE_VIDEO_BURST |
|
|
+ MIPI_DSI_MODE_NO_EOT_PACKET |
|
|
+ MIPI_DSI_MODE_LPM;
|
|
+
|
|
+ ret = mipi_dsi_attach(dsi);
|
|
+ if (ret < 0) {
|
|
+ drm_panel_remove(&ctx->panel);
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static void boe_dsi_remove(struct mipi_dsi_device *dsi)
|
|
+{
|
|
+ struct boe *ctx = mipi_dsi_get_drvdata(dsi);
|
|
+
|
|
+ mipi_dsi_detach(dsi);
|
|
+ drm_panel_remove(&ctx->panel);
|
|
+}
|
|
+
|
|
+static const struct of_device_id boe_of_match[] = {
|
|
+ { .compatible = "boe,th101mb31ig002-28a", },
|
|
+ { /* sentinel */ }
|
|
+};
|
|
+MODULE_DEVICE_TABLE(of, boe_of_match);
|
|
+
|
|
+static struct mipi_dsi_driver boe_driver = {
|
|
+ .driver = {
|
|
+ .name = "boe-th101mb31ig002-28a",
|
|
+ .of_match_table = boe_of_match,
|
|
+ },
|
|
+ .probe = boe_dsi_probe,
|
|
+ .remove = boe_dsi_remove,
|
|
+};
|
|
+module_mipi_dsi_driver(boe_driver);
|
|
+
|
|
+MODULE_AUTHOR("Alexander Warnecke <awarnecke002@hotmail.com>");
|
|
+MODULE_DESCRIPTION("BOE TH101MB31IG002-28A MIPI-DSI LCD panel");
|
|
+MODULE_LICENSE("GPL");
|
|
--
|
|
2.34.1
|
|
|