Files
BPI-CM9-Linux/build/patch/kernel/archive/sm8550-6.18/0104-drm-panel-Add-Retroid-Pocket-6-panel.patch
T

438 lines
14 KiB
Diff

From 03384ed4b30f9488d2653baa7871cacb7cdd99c5 Mon Sep 17 00:00:00 2001
From: spycat88 <spycat88@users.noreply.github.com>
Date: Thu, 22 Jan 2026 22:57:15 +0000
Subject: [PATCH] drm/panel: Add Retroid Pocket 6 panel
---
drivers/gpu/drm/panel/Kconfig | 9 +
drivers/gpu/drm/panel/Makefile | 1 +
.../gpu/drm/panel/panel-retroid-pocket-6.c | 384 ++++++++++++++++++
3 files changed, 394 insertions(+)
create mode 100644 drivers/gpu/drm/panel/panel-retroid-pocket-6.c
diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
index 7a83804fedca..9878d078d83a 100644
--- a/drivers/gpu/drm/panel/Kconfig
+++ b/drivers/gpu/drm/panel/Kconfig
@@ -709,6 +709,15 @@ config DRM_PANEL_RENESAS_R69328
This panel controller can be found in LG Optimus 4X P895 smartphone
in combination with LCD panel.
+config DRM_PANEL_RETROID_POCKET_6
+ tristate "Retroid Pocket 6 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 Retroid Pocket 6
+ panel.
+
config DRM_PANEL_RONBO_RB070D30
tristate "Ronbo Electronics RB070D30 panel"
depends on OF
diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
index b9562a6fdcb3..b18e2251761e 100644
--- a/drivers/gpu/drm/panel/Makefile
+++ b/drivers/gpu/drm/panel/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_DRM_PANEL_RAYDIUM_RM692E5) += panel-raydium-rm692e5.o
obj-$(CONFIG_DRM_PANEL_RAYDIUM_RM69380) += panel-raydium-rm69380.o
obj-$(CONFIG_DRM_PANEL_RENESAS_R61307) += panel-renesas-r61307.o
obj-$(CONFIG_DRM_PANEL_RENESAS_R69328) += panel-renesas-r69328.o
+obj-$(CONFIG_DRM_PANEL_RETROID_POCKET_6) += panel-retroid-pocket-6.o
obj-$(CONFIG_DRM_PANEL_RONBO_RB070D30) += panel-ronbo-rb070d30.o
obj-$(CONFIG_DRM_PANEL_SAMSUNG_AMS581VF01) += panel-samsung-ams581vf01.o
obj-$(CONFIG_DRM_PANEL_SAMSUNG_AMS639RQ08) += panel-samsung-ams639rq08.o
diff --git a/drivers/gpu/drm/panel/panel-retroid-pocket-6.c b/drivers/gpu/drm/panel/panel-retroid-pocket-6.c
new file mode 100644
index 000000000000..49f78afd85d5
--- /dev/null
+++ b/drivers/gpu/drm/panel/panel-retroid-pocket-6.c
@@ -0,0 +1,384 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2026 ROCKNIX Team <https://rocknix.org>
+ * Generated based on vendor device tree.
+ */
+
+#include <linux/backlight.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/regulator/consumer.h>
+
+#include <video/mipi_display.h>
+
+#include <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+#include <drm/drm_mipi_dsi.h>
+#include <drm/drm_modes.h>
+#include <drm/drm_panel.h>
+#include <drm/drm_probe_helper.h>
+
+struct retroid_pocket_6_panel {
+ struct drm_panel panel;
+ struct mipi_dsi_device *dsi;
+ struct drm_dsc_config dsc;
+ struct gpio_desc *reset_gpio;
+ struct regulator_bulk_data *supplies;
+ enum drm_panel_orientation orientation;
+};
+
+static const struct regulator_bulk_data panel_supplies[] = {
+ { .supply = "avdd" },
+ { .supply = "vci" },
+ { .supply = "vddio" },
+};
+
+static inline
+struct retroid_pocket_6_panel *to_retroid_pocket_6_panel(struct drm_panel *panel)
+{
+ return container_of(panel, struct retroid_pocket_6_panel, panel);
+}
+
+static void retroid_pocket_6_panel_reset(struct retroid_pocket_6_panel *ctx)
+{
+ gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+ msleep(20);
+ gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+ msleep(20);
+ gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+ msleep(20);
+}
+
+static int retroid_pocket_6_panel_on(struct retroid_pocket_6_panel *ctx)
+{
+ struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi };
+
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x03, 0x01);
+ mipi_dsi_dcs_set_tear_on_multi(&dsi_ctx, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, MIPI_DCS_WRITE_CONTROL_DISPLAY, 0x20);
+ mipi_dsi_dcs_set_display_brightness_multi(&dsi_ctx, 0xff07);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x6f, 0x02);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, MIPI_DCS_SET_ADDRESS_MODE, 0x02);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x59, 0x00);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x6c, 0x00);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x6d, 0x00);
+
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x70,
+ 0x11, 0x00, 0x00, 0x89, 0x30, 0x80, 0x07,
+ 0x80, 0x04, 0x38, 0x00, 0x14, 0x02, 0x1c,
+ 0x02, 0x1c, 0x02, 0x00, 0x02, 0x25, 0x00,
+ 0x20, 0x01, 0xd5, 0x00, 0x07, 0x00, 0x0d,
+ 0x05, 0x7a, 0x05, 0x16, 0x18, 0x00, 0x10,
+ 0xf0, 0x03, 0x0c, 0x20, 0x00, 0x06, 0x0b,
+ 0x0b, 0x33, 0x0e, 0x1c, 0x2a, 0x38, 0x46,
+ 0x54, 0x62, 0x69, 0x70, 0x77, 0x79, 0x7b,
+ 0x7d, 0x7e, 0x01, 0x02, 0x01, 0x00, 0x09,
+ 0x40, 0x09, 0xbe, 0x19, 0xfc, 0x19, 0xfa,
+ 0x19, 0xf8, 0x1a, 0x38, 0x1a, 0x78, 0x1a,
+ 0xb6, 0x2a, 0xb6, 0x2a, 0xf4, 0x2a, 0xf4,
+ 0x4b, 0x34, 0x63, 0x74, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00);
+
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf0, 0xaa, 0x10);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb1,
+ 0x02, 0x15, 0x00, 0x14, 0x00, 0x20, 0x00,
+ 0x02, 0x16, 0x00, 0x14, 0x07, 0xb4, 0x00,
+ 0x02, 0x16, 0x00, 0x14, 0x00, 0x10, 0x00);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf0, 0xaa, 0x14);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb2, 0x03, 0x33);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb4,
+ 0x0a, 0x72, 0x00, 0x00, 0x0a, 0x72, 0x00,
+ 0x00, 0x0a, 0x72, 0x00, 0x00);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb5,
+ 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
+ 0x06, 0x01);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb9,
+ 0x00, 0x00, 0x08, 0x1e, 0x1e, 0x1e);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xbc,
+ 0x10, 0x00, 0x00, 0x08, 0x11, 0x1e, 0x7c,
+ 0x1e, 0x7c, 0x1e, 0x7c);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xbe,
+ 0x10, 0x10, 0x00, 0x0c, 0x22, 0x1e, 0x62,
+ 0x1e, 0x62, 0x1e, 0x62);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0x80);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x65, 0x13);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xfd, 0x01);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0x81);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x65, 0x05);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf3, 0x0f);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0x82);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf9, 0x00);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0x83);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x65, 0x04);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf8, 0x00);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf0, 0xaa, 0x00);
+ mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0x00);
+
+ mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
+ mipi_dsi_msleep(&dsi_ctx, 150);
+ mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
+ mipi_dsi_msleep(&dsi_ctx, 50);
+
+ return dsi_ctx.accum_err;
+}
+
+static int retroid_pocket_6_panel_off(struct retroid_pocket_6_panel *ctx)
+{
+ struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi };
+
+ mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
+ mipi_dsi_msleep(&dsi_ctx, 20);
+ mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
+ mipi_dsi_msleep(&dsi_ctx, 120);
+
+ return dsi_ctx.accum_err;
+}
+
+static int retroid_pocket_6_panel_prepare(struct drm_panel *panel)
+{
+ struct retroid_pocket_6_panel *ctx = to_retroid_pocket_6_panel(panel);
+ struct device *dev = &ctx->dsi->dev;
+ struct drm_dsc_picture_parameter_set pps;
+ int ret;
+
+ ret = regulator_bulk_enable(ARRAY_SIZE(panel_supplies), ctx->supplies);
+ if (ret < 0) {
+ dev_err(panel->dev, "Failed to enable regulators: %d\n", ret);
+ return ret;
+ }
+ msleep(20);
+
+ retroid_pocket_6_panel_reset(ctx);
+
+ ret = retroid_pocket_6_panel_on(ctx);
+ if (ret < 0) {
+ dev_err(dev, "Failed to initialize panel: %d\n", ret);
+ gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+ return ret;
+ }
+
+ drm_dsc_pps_payload_pack(&pps, &ctx->dsc);
+
+ ret = mipi_dsi_picture_parameter_set(ctx->dsi, &pps);
+ if (ret < 0) {
+ dev_err(panel->dev, "Failed to transmit PPS: %d\n", ret);
+ return ret;
+ }
+
+ ret = mipi_dsi_compression_mode(ctx->dsi, true);
+ if (ret < 0) {
+ dev_err(dev, "Failed to enable compression mode: %d\n", ret);
+ return ret;
+ }
+
+ msleep(28);
+
+ return 0;
+}
+
+static int retroid_pocket_6_panel_unprepare(struct drm_panel *panel)
+{
+ struct retroid_pocket_6_panel *ctx = to_retroid_pocket_6_panel(panel);
+ struct device *dev = &ctx->dsi->dev;
+ int ret;
+
+ ret = retroid_pocket_6_panel_off(ctx);
+ if (ret < 0)
+ dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+ regulator_bulk_disable(ARRAY_SIZE(panel_supplies), ctx->supplies);
+ gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+
+ return 0;
+}
+
+static const struct drm_display_mode retroid_pocket_6_panel_mode = {
+ .clock = (1080 + 22 + 2 + 16) * (1920 + 16 + 2 + 20) * 120 / 1000,
+ .hdisplay = 1080,
+ .hsync_start = 1080 + 22,
+ .hsync_end = 1080 + 22 + 2,
+ .htotal = 1080 + 22 + 2 + 16,
+ .vdisplay = 1920,
+ .vsync_start = 1920 + 16,
+ .vsync_end = 1920 + 16 + 2,
+ .vtotal = 1920 + 16 + 2 + 20,
+ .width_mm = 0,
+ .height_mm = 0,
+ .type = DRM_MODE_TYPE_DRIVER,
+};
+
+static int retroid_pocket_6_panel_get_modes(struct drm_panel *panel,
+ struct drm_connector *connector)
+{
+ return drm_connector_helper_get_modes_fixed(connector,
+ &retroid_pocket_6_panel_mode);
+}
+
+static enum drm_panel_orientation retroid_pocket_6_panel_get_orientation(struct drm_panel *panel)
+{
+ struct retroid_pocket_6_panel *ctx = to_retroid_pocket_6_panel(panel);
+
+ return ctx->orientation;
+}
+
+static const struct drm_panel_funcs retroid_pocket_6_panel_funcs = {
+ .prepare = retroid_pocket_6_panel_prepare,
+ .unprepare = retroid_pocket_6_panel_unprepare,
+ .get_modes = retroid_pocket_6_panel_get_modes,
+ .get_orientation = retroid_pocket_6_panel_get_orientation,
+};
+
+static int retroid_pocket_6_panel_bl_update_status(struct backlight_device *bl)
+{
+ struct mipi_dsi_device *dsi = bl_get_data(bl);
+ u16 brightness = backlight_get_brightness(bl);
+ int ret;
+
+ dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+ ret = mipi_dsi_dcs_set_display_brightness_large(dsi, brightness);
+ if (ret < 0)
+ return ret;
+
+ dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+ return 0;
+}
+
+static int retroid_pocket_6_panel_bl_get_brightness(struct backlight_device *bl)
+{
+ struct mipi_dsi_device *dsi = bl_get_data(bl);
+ u16 brightness;
+ int ret;
+
+ dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+ ret = mipi_dsi_dcs_get_display_brightness_large(dsi, &brightness);
+ if (ret < 0)
+ return ret;
+
+ dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+ return brightness;
+}
+
+static const struct backlight_ops retroid_pocket_6_panel_bl_ops = {
+ .update_status = retroid_pocket_6_panel_bl_update_status,
+ .get_brightness = retroid_pocket_6_panel_bl_get_brightness,
+};
+
+static struct backlight_device *
+retroid_pocket_6_panel_create_backlight(struct mipi_dsi_device *dsi)
+{
+ struct device *dev = &dsi->dev;
+ const struct backlight_properties props = {
+ .type = BACKLIGHT_RAW,
+ .brightness = 4095,
+ .max_brightness = 4095,
+ };
+
+ return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+ &retroid_pocket_6_panel_bl_ops, &props);
+}
+
+static int retroid_pocket_6_panel_probe(struct mipi_dsi_device *dsi)
+{
+ struct device *dev = &dsi->dev;
+ struct retroid_pocket_6_panel *ctx;
+ int ret;
+
+ ctx = devm_drm_panel_alloc(dev, struct retroid_pocket_6_panel, panel,
+ &retroid_pocket_6_panel_funcs,
+ DRM_MODE_CONNECTOR_DSI);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ ret = devm_regulator_bulk_get_const(dev, ARRAY_SIZE(panel_supplies),
+ panel_supplies, &ctx->supplies);
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "Failed to get regulators\n");
+
+ ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+ if (IS_ERR(ctx->reset_gpio))
+ return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio),
+ "Failed to get reset-gpios\n");
+
+ ctx->dsi = dsi;
+ mipi_dsi_set_drvdata(dsi, ctx);
+
+ dsi->lanes = 4;
+ dsi->format = MIPI_DSI_FMT_RGB888;
+ dsi->mode_flags = MIPI_DSI_MODE_NO_EOT_PACKET |
+ MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_LPM;
+
+ ret = of_drm_get_panel_orientation(dev->of_node, &ctx->orientation);
+ if (ret < 0) {
+ dev_err(dev, "Failed to get orientation %d\n", ret);
+ return ret;
+ }
+
+ ctx->panel.prepare_prev_first = true;
+
+ ctx->panel.backlight = retroid_pocket_6_panel_create_backlight(dsi);
+ if (IS_ERR(ctx->panel.backlight))
+ return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight),
+ "Failed to create backlight\n");
+
+ drm_panel_add(&ctx->panel);
+
+ /* This panel only supports DSC; unconditionally enable it */
+ dsi->dsc = &ctx->dsc;
+
+ ctx->dsc.dsc_version_major = 1;
+ ctx->dsc.dsc_version_minor = 1;
+
+ /* DSC slice configuration derived from hardware dump */
+ ctx->dsc.slice_height = 12;
+ ctx->dsc.slice_width = 540;
+ ctx->dsc.slice_count = 1080 / ctx->dsc.slice_width;
+ ctx->dsc.bits_per_component = 8;
+ ctx->dsc.bits_per_pixel = 8 << 4; /* 8 bpp */
+ ctx->dsc.block_pred_enable = true;
+
+ ret = mipi_dsi_attach(dsi);
+ if (ret < 0) {
+ drm_panel_remove(&ctx->panel);
+ return dev_err_probe(dev, ret, "Failed to attach to DSI host\n");
+ }
+
+ return 0;
+}
+
+static void retroid_pocket_6_panel_remove(struct mipi_dsi_device *dsi)
+{
+ struct retroid_pocket_6_panel *ctx = mipi_dsi_get_drvdata(dsi);
+ int ret;
+
+ ret = mipi_dsi_detach(dsi);
+ if (ret < 0)
+ dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
+
+ drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id retroid_pocket_6_panel_of_match[] = {
+ { .compatible = "retroid,pocket-6-panel" },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, retroid_pocket_6_panel_of_match);
+
+static struct mipi_dsi_driver retroid_pocket_6_panel_driver = {
+ .probe = retroid_pocket_6_panel_probe,
+ .remove = retroid_pocket_6_panel_remove,
+ .driver = {
+ .name = "panel-retroid-pocket-6",
+ .of_match_table = retroid_pocket_6_panel_of_match,
+ },
+};
+module_mipi_dsi_driver(retroid_pocket_6_panel_driver);
+
+MODULE_AUTHOR("ROCKNIX Team <https://rocknix.org>");
+MODULE_DESCRIPTION("DRM driver for Retroid Pocket 6 dsi panel");
+MODULE_LICENSE("GPL");
--
2.34.1