Skip to contentSkip to conversation

drm/panel: Add panel driver for ChipWealth CH13726A based panels

PATCH Superseded Aaron Kling 3 participants 6 messages Apr 8 – Apr 16

Subsystems (4)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover drm/panel: Add panel driver for ChipWealth CH13726A based panels

This driver is based on the one by Teguh Sobirin [0], cut down to only support the AYN Thor bottom panel.

Due to [1], the AYN vendor description patch has been folded into the AYN QCS8550 dt series. Which means this series now depends on said series and it must be picked up before this.

[0] https://github.com/AYNTechnologies/linux/commit/d0ff75b09e66023c5f88992706dee4601aa7a437
[1] https://lore.kernel.org/linux-arm-msm/[email protected]

---
Changes in v4:
- Add fallback compatible to bindings doc in patch 1
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Reword patch 1 commit message for clarity
- Order properties properly in patch 1
- Track vendor description dependency series change
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Add Neil Armstrong to binding maintainer list
- Add 120hz mode, which required a minor restructure of the driver
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Aaron Kling (1):
dt-bindings: display: panel: Add ChipWealth CH13726A AMOLED driver

Teguh Sobirin (1):
drm/panel: Add panel driver for ChipWealth CH13726A based panels

 .../display/panel/chipwealth,ch13726a.yaml         |  67 ++++
 drivers/gpu/drm/panel/Kconfig                      |  11 +
 drivers/gpu/drm/panel/Makefile                     |   1 +
 drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c  | 339 +++++++++++++++++++++
 4 files changed, 418 insertions(+)

---
base-commit: 785f0eb2f85decbe7c1ef9ae922931f0194ffc2e
change-id: 20260220-ch13726a-59c6678d53d8
prerequisite-change-id: 20260217-ayn-qcs8550-16c07b63de26:v4
prerequisite-patch-id: 042cab8f04748207ba5395dd0f23c445955aaa2b
prerequisite-patch-id: 4e13275bfaa4f838a627fe8dfa3d4cb8972fc5b4
prerequisite-patch-id: 16c130bcfd7c787b91e828b8e600bd0d740f937e
prerequisite-patch-id: 4b7e6b017349c386f54e221790da4392fe066ff3
prerequisite-patch-id: 3844bef2eda3cf59031b1d131eb6ba9295629bb4
prerequisite-patch-id: bcb261e40f0386b91a09eb4080cbdf74d21f3df2

Best regards,

Signature · 1 line
Aaron Kling <[email protected]>
#1 lore raw

PATCH v4 1/2 dt-bindings: display: panel: Add ChipWealth CH13726A AMOLED driver

The Chip Wealth Technology CH13726A AMOLED driver is a single chip solution for MIPI-DSI. This is used for the AYN Thor bottom panel.

---
 .../display/panel/chipwealth,ch13726a.yaml         | 67 ++++++++++++++++++++++
 1 file changed, 67 insertions(+)
Documentation/devicetree/bindings/display/panel/chipwealth,ch13726a.yaml new file +67 -0
new file mode 100644
index 00000000000000..c8d7b61037e622
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/panel/chipwealth,ch13726a.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Chip Wealth Technology CH13726A AMOLED driver
+
+maintainers:
+  - Neil Armstrong <[email protected]>
+
+description:
+  Chip Wealth Technology CH13726A is a single-chip solution
+  for AMOLED connected using a MIPI-DSI video interface.
+
+allOf:
+  - $ref: panel-common.yaml#
+
+properties:
+  compatible:
+    items:
+      - const: ayntec,thor-panel-bottom
+      - const: chipwealth,ch13726a
+
+  reg:
+    maxItems: 1
+    description: DSI virtual channel
+
+  vdd-supply: true
+  vddio-supply: true
+  vdd1v2-supply: true
+  avdd-supply: true
+
+  port: true
+  reset-gpios: true
+  rotation: true
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+  - vddio-supply
+  - vdd1v2-supply
+  - avdd-supply
+  - reset-gpios
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    dsi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        panel@0 {
+            compatible = "ayntec,thor-panel-bottom", "chipwealth,ch13726a";
+            reg = <0>;
+            vdd1v2-supply = <&vreg_l11b_1p2>;
+            vddio-supply = <&vdd_disp_1v8>;
+            vdd-supply = <&vreg_l13b_3p0>;
+            avdd-supply = <&vdd_disp2_2v8>;
+            reset-gpios = <&tlmm 133 GPIO_ACTIVE_HIGH>;
+        };
+    };
+
+...
Signature · 1 line
2.53.0
Reviewed-by on v4 1/2
#2 lore raw

Re: [PATCH v4 1/2] dt-bindings: display: panel: Add ChipWealth CH13726A AMOLED driver

Quoted 7 lines · Aaron Kling

The Chip Wealth Technology CH13726A AMOLED driver is a single chip solution for MIPI-DSI. This is used for the AYN Thor bottom panel.

---
 .../display/panel/chipwealth,ch13726a.yaml         | 67 ++++++++++++++++++++++
 1 file changed, 67 insertions(+)

Best regards,
Krzysztof

#3 lore raw

PATCH v4 2/2 drm/panel: Add panel driver for ChipWealth CH13726A based panels

In reply to Aaron Kling

From: Teguh Sobirin <[email protected]>

This is used by the AYN Thor for the bottom panel.

---
 drivers/gpu/drm/panel/Kconfig                     |  11 +
 drivers/gpu/drm/panel/Makefile                    |   1 +
 drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c | 339 ++++++++++++++++++++++
 3 files changed, 351 insertions(+)
drivers/gpu/drm/panel/Kconfig +11 -0
index d6863b28ddc559..e2c00f08f4507d 100644
@@ -105,6 +105,17 @@ config DRM_PANEL_BOE_TV101WUM_LL2
 	  Say Y here if you want to support for BOE TV101WUM-LL2
 	  WUXGA PANEL DSI Video Mode panel
 
+config DRM_PANEL_CHIPWEALTH_CH13726A
+	tristate "CHIPWEALTH CH13726A-based DSI panel"
+	depends on OF
+	depends on DRM_MIPI_DSI
+	depends on BACKLIGHT_CLASS_DEVICE
+	select DRM_DISPLAY_DP_HELPER
+	select DRM_DISPLAY_HELPER
+	help
+	  Say Y here if you want to enable support for ChipWealth
+	  CH13726A-based display panels.
+
 config DRM_PANEL_EBBG_FT8719
 	tristate "EBBG FT8719 panel driver"
 	depends on OF
drivers/gpu/drm/panel/Makefile +1 -0
index a4291dc3905bed..343d283d1620fb 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_DRM_PANEL_BOE_TD4320) += panel-boe-td4320.o
 obj-$(CONFIG_DRM_PANEL_BOE_TH101MB31UIG002_28A) += panel-boe-th101mb31ig002-28a.o
 obj-$(CONFIG_DRM_PANEL_BOE_TV101WUM_LL2) += panel-boe-tv101wum-ll2.o
 obj-$(CONFIG_DRM_PANEL_BOE_TV101WUM_NL6) += panel-boe-tv101wum-nl6.o
+obj-$(CONFIG_DRM_PANEL_CHIPWEALTH_CH13726A) += panel-chipwealth-ch13726a.o
 obj-$(CONFIG_DRM_PANEL_DSI_CM) += panel-dsi-cm.o
 obj-$(CONFIG_DRM_PANEL_LVDS) += panel-lvds.o
 obj-$(CONFIG_DRM_PANEL_SIMPLE) += panel-simple.o
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +339 -0

339 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#4 lore raw
Quoted 70 lines · On 4/8/26 07:32, Aaron Kling via B4 Relay wrote:

From: Teguh Sobirin <[email protected]>

This is used by the AYN Thor for the bottom panel.

---
  drivers/gpu/drm/panel/Kconfig                     |  11 +
  drivers/gpu/drm/panel/Makefile                    |   1 +
  drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c | 339 ++++++++++++++++++++++
  3 files changed, 351 insertions(+)
drivers/gpu/drm/panel/Kconfig +11 -0
index d6863b28ddc559..e2c00f08f4507d 100644
@@ -105,6 +105,17 @@ config DRM_PANEL_BOE_TV101WUM_LL2
  	  Say Y here if you want to support for BOE TV101WUM-LL2
  	  WUXGA PANEL DSI Video Mode panel
 
+config DRM_PANEL_CHIPWEALTH_CH13726A
+	tristate "CHIPWEALTH CH13726A-based DSI panel"
+	depends on OF
+	depends on DRM_MIPI_DSI
+	depends on BACKLIGHT_CLASS_DEVICE
+	select DRM_DISPLAY_DP_HELPER
+	select DRM_DISPLAY_HELPER
+	help
+	  Say Y here if you want to enable support for ChipWealth
+	  CH13726A-based display panels.
+
  config DRM_PANEL_EBBG_FT8719
  	tristate "EBBG FT8719 panel driver"
  	depends on OF
drivers/gpu/drm/panel/Makefile +1 -0
index a4291dc3905bed..343d283d1620fb 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_DRM_PANEL_BOE_TD4320) += panel-boe-td4320.o
  obj-$(CONFIG_DRM_PANEL_BOE_TH101MB31UIG002_28A) += panel-boe-th101mb31ig002-28a.o
  obj-$(CONFIG_DRM_PANEL_BOE_TV101WUM_LL2) += panel-boe-tv101wum-ll2.o
  obj-$(CONFIG_DRM_PANEL_BOE_TV101WUM_NL6) += panel-boe-tv101wum-nl6.o
+obj-$(CONFIG_DRM_PANEL_CHIPWEALTH_CH13726A) += panel-chipwealth-ch13726a.o
  obj-$(CONFIG_DRM_PANEL_DSI_CM) += panel-dsi-cm.o
  obj-$(CONFIG_DRM_PANEL_LVDS) += panel-lvds.o
  obj-$(CONFIG_DRM_PANEL_SIMPLE) += panel-simple.o
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +17 -0
new file mode 100644
index 00000000000000..48a5e20e07c487
@@ -0,0 +1,339 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ChipWealth CH13726A MIPI-DSI panel driver
+ * Copyright (c) 2024, Teguh Sobirin <[email protected]>.
+ */
+
+#include <linux/backlight.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/regulator/consumer.h>
+
+#include <drm/drm_mipi_dsi.h>
+#include <drm/drm_modes.h>
+#include <drm/drm_panel.h>
+

drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c line 27

Quoted 10 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +10 -0
+#include <video/mipi_display.h>
+
+struct ch13726a_panel {
+	struct drm_panel panel;
+	struct mipi_dsi_device *dsi;
+	struct regulator_bulk_data supplies[4];
+	struct gpio_desc *reset_gpio;
+	struct ch13726a_desc *desc;
+	enum drm_panel_orientation orientation;
+	bool prepared;

Drop this, it's handled by the panel core now.

Quoted 142 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +142 -0
+};
+
+struct ch13726a_desc {
+	unsigned int width_mm;
+	unsigned int height_mm;
+	unsigned int bpc;
+
+	const struct drm_display_mode *modes;
+	unsigned int num_modes;
+};
+
+static inline struct ch13726a_panel *to_ch13726a_panel(struct drm_panel *panel)
+{
+	return container_of(panel, struct ch13726a_panel, panel);
+}
+
+static void ch13726a_reset(struct ch13726a_panel *ctx)
+{
+	gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+	usleep_range(10000, 11000);
+	gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+	usleep_range(10000, 11000);
+	gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+	usleep_range(10000, 11000);
+}
+
+static int ch13726a_on(struct ch13726a_panel *ctx)
+{
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi };
+
+	ctx->dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+	mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xf0, 0x50);
+	mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xb9, 0x00);
+
+	mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
+
+	mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
+
+	return dsi_ctx.accum_err;
+}
+
+static int ch13726a_disable(struct drm_panel *panel)
+{
+	struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi };
+
+	ctx->dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+	mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
+	mipi_dsi_msleep(&dsi_ctx, 50);
+	mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
+
+	return dsi_ctx.accum_err;
+}
+
+static int ch13726a_prepare(struct drm_panel *panel)
+{
+	struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+	struct device *dev = &ctx->dsi->dev;
+	int ret;
+
+	if (ctx->prepared)
+		return 0;
+
+	ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+	if (ret < 0) {
+		dev_err(dev, "Failed to enable regulators: %d\n", ret);
+		return ret;
+	}
+
+	ch13726a_reset(ctx);
+
+	ret = ch13726a_on(ctx);
+	if (ret < 0) {
+		dev_err(dev, "Failed to initialize panel: %d\n", ret);
+		gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+		regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+		return ret;
+	}
+
+	msleep(28);
+
+	ctx->prepared = true;
+
+	return 0;
+}
+
+static int ch13726a_unprepare(struct drm_panel *panel)
+{
+	struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+
+	if (!ctx->prepared)
+		return 0;
+
+	gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+	regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+	ctx->prepared = false;
+	return 0;
+}
+
+static const struct drm_display_mode thor_bottom_modes[] = {
+	{
+		/* 120Hz */
+		.clock = (1080 + 28 + 4 + 36) * (1240 + 16 + 4 + 8) * 120 / 1000,
+		.hdisplay = 1080,
+		.hsync_start = 1080 + 28,
+		.hsync_end = 1080 + 28 + 4,
+		.htotal = 1080 + 28 + 4 + 36,
+		.vdisplay = 1240,
+		.vsync_start = 1240 + 16,
+		.vsync_end = 1240 + 16 + 4,
+		.vtotal = 1240 + 16 + 4 + 8,
+	},
+	{
+		/* 60Hz */
+		.clock = (1080 + 28 + 4 + 36) * (1240 + 16 + 4 + 8) * 60 / 1000,
+		.hdisplay = 1080,
+		.hsync_start = 1080 + 28,
+		.hsync_end = 1080 + 28 + 4,
+		.htotal = 1080 + 28 + 4 + 36,
+		.vdisplay = 1240,
+		.vsync_start = 1240 + 16,
+		.vsync_end = 1240 + 16 + 4,
+		.vtotal = 1240 + 16 + 4 + 8,
+	}
+};
+
+static struct ch13726a_desc thor_bottom_desc = {
+	.modes = thor_bottom_modes,
+	.num_modes = ARRAY_SIZE(thor_bottom_modes),
+	.width_mm = 65,
+	.height_mm = 75,
+	.bpc = 8,
+};
+
+static int ch13726a_get_modes(struct drm_panel *panel,
+					struct drm_connector *connector)
+{
+	struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+

drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c line 179

Quoted 10 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +10 -0
+	for (uint8_t i = 0; i < ctx->desc->num_modes; i++) {
+		const struct drm_display_mode *m = &ctx->desc->modes[i];
+		struct drm_display_mode *mode;
+
+		mode = drm_mode_duplicate(connector->dev, m);
+		if (!mode) {
+			dev_err(&ctx->dsi->dev, "failed to add mode %ux%u@%u\n",
+				m->hdisplay, m->vdisplay, drm_mode_vrefresh(m));
+			return -ENOMEM;
+		}

Can you use drm_connector_helper_get_modes_fixed instead ?

Quoted 80 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +80 -0
+
+		mode->type = DRM_MODE_TYPE_DRIVER;
+		if (i == 0)
+			mode->type |= DRM_MODE_TYPE_PREFERRED;
+
+		drm_mode_set_name(mode);
+		drm_mode_probed_add(connector, mode);
+	}
+
+	connector->display_info.width_mm = ctx->desc->width_mm;
+	connector->display_info.height_mm = ctx->desc->height_mm;
+	connector->display_info.bpc = ctx->desc->bpc;
+
+	return ctx->desc->num_modes;
+}
+
+static enum drm_panel_orientation ch13726a_get_orientation(struct drm_panel *panel)
+{
+	struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+
+	return ctx->orientation;
+}
+
+static const struct drm_panel_funcs ch13726a_panel_funcs = {
+	.prepare = ch13726a_prepare,
+	.unprepare = ch13726a_unprepare,
+	.disable = ch13726a_disable,
+	.get_modes = ch13726a_get_modes,
+	.get_orientation = ch13726a_get_orientation,
+};
+
+static int ch13726a_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(dsi, brightness);
+	if (ret < 0)
+		return ret;
+
+	dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+	return 0;
+}
+
+static const struct backlight_ops ch13726a_bl_ops = {
+	.update_status = ch13726a_bl_update_status,
+};
+
+static struct backlight_device *
+ch13726a_create_backlight(struct mipi_dsi_device *dsi)
+{
+	struct device *dev = &dsi->dev;
+	const struct backlight_properties props = {
+		.type = BACKLIGHT_RAW,
+		.brightness = 255,
+		.max_brightness = 255,
+	};
+
+	return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+					      &ch13726a_bl_ops, &props);
+}
+
+static int ch13726a_probe(struct mipi_dsi_device *dsi)
+{
+	struct device *dev = &dsi->dev;
+	struct ch13726a_panel *ctx;
+	int ret;
+
+	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return -ENOMEM;
+
+	ctx->desc = (struct ch13726a_desc *)of_device_get_match_data(dev);
+	if (!ctx->desc)
+		return -ENODEV;
+

drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c line 269

Quoted 10 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +10 -0
+	ctx->supplies[0].supply = "vdd1v2";
+	ctx->supplies[1].supply = "vddio";
+	ctx->supplies[2].supply = "vdd";
+	ctx->supplies[3].supply = "avdd";
+
+	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
+				      ctx->supplies);
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Failed to get regulators\n");
+

Can you switch to devm_regulator_bulk_get_const ?

Quoted 11 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +11 -0
+	ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(ctx->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio),
+				     "Failed to get reset-gpios\n");
+
+	ret = of_drm_get_panel_orientation(dev->of_node, &ctx->orientation);
+	if (ret < 0) {
+		dev_err(dev, "%pOF: failed to get orientation %d\n", dev->of_node, ret);
+		return ret;
+	}
+

drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c line 290

Quoted 10 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +10 -0
+	ctx->dsi = dsi;
+	mipi_dsi_set_drvdata(dsi, ctx);
+
+	dsi->lanes = 4;
+	dsi->format = MIPI_DSI_FMT_RGB888;
+	dsi->mode_flags = MIPI_DSI_MODE_VIDEO |
+			  MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+	drm_panel_init(&ctx->panel, dev, &ch13726a_panel_funcs,
+		       DRM_MODE_CONNECTOR_DSI);

Please use devm_drm_panel_alloc() instead.

Quoted 50 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +49 -0
+	ctx->panel.prepare_prev_first = true;
+
+	ctx->panel.backlight = ch13726a_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);
+
+	ret = mipi_dsi_attach(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
+		drm_panel_remove(&ctx->panel);
+		return ret;
+	}
+
+	return 0;
+}
+
+static void ch13726a_remove(struct mipi_dsi_device *dsi)
+{
+	struct ch13726a_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 ch13726a_of_match[] = {
+	{ .compatible = "ayntec,thor-panel-bottom", .data = &thor_bottom_desc },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, ch13726a_of_match);
+
+static struct mipi_dsi_driver ch13726a_driver = {
+	.probe = ch13726a_probe,
+	.remove = ch13726a_remove,
+	.driver = {
+		.name = "panel-ch13726a-amoled",
+		.of_match_table = ch13726a_of_match,
+	},
+};
+module_mipi_dsi_driver(ch13726a_driver);
+
+MODULE_DESCRIPTION("DRM driver for CH13726A DSI panels");
+MODULE_LICENSE("GPL");
#5 lore raw
Quoted 76 lines · Neil Armstrong
Quoted 74 lines · On 4/8/26 07:32, Aaron Kling via B4 Relay wrote:

From: Teguh Sobirin <[email protected]>

This is used by the AYN Thor for the bottom panel.

---
  drivers/gpu/drm/panel/Kconfig                     |  11 +
  drivers/gpu/drm/panel/Makefile                    |   1 +
  drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c | 339 ++++++++++++++++++++++
  3 files changed, 351 insertions(+)
drivers/gpu/drm/panel/Kconfig +11 -0
index d6863b28ddc559..e2c00f08f4507d 100644
@@ -105,6 +105,17 @@ config DRM_PANEL_BOE_TV101WUM_LL2
        Say Y here if you want to support for BOE TV101WUM-LL2
        WUXGA PANEL DSI Video Mode panel
 
+config DRM_PANEL_CHIPWEALTH_CH13726A
+     tristate "CHIPWEALTH CH13726A-based DSI panel"
+     depends on OF
+     depends on DRM_MIPI_DSI
+     depends on BACKLIGHT_CLASS_DEVICE
+     select DRM_DISPLAY_DP_HELPER
+     select DRM_DISPLAY_HELPER
+     help
+       Say Y here if you want to enable support for ChipWealth
+       CH13726A-based display panels.
+
  config DRM_PANEL_EBBG_FT8719
      tristate "EBBG FT8719 panel driver"
      depends on OF
drivers/gpu/drm/panel/Makefile +1 -0
index a4291dc3905bed..343d283d1620fb 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_DRM_PANEL_BOE_TD4320) += panel-boe-td4320.o
  obj-$(CONFIG_DRM_PANEL_BOE_TH101MB31UIG002_28A) += panel-boe-th101mb31ig002-28a.o
  obj-$(CONFIG_DRM_PANEL_BOE_TV101WUM_LL2) += panel-boe-tv101wum-ll2.o
  obj-$(CONFIG_DRM_PANEL_BOE_TV101WUM_NL6) += panel-boe-tv101wum-nl6.o
+obj-$(CONFIG_DRM_PANEL_CHIPWEALTH_CH13726A) += panel-chipwealth-ch13726a.o
  obj-$(CONFIG_DRM_PANEL_DSI_CM) += panel-dsi-cm.o
  obj-$(CONFIG_DRM_PANEL_LVDS) += panel-lvds.o
  obj-$(CONFIG_DRM_PANEL_SIMPLE) += panel-simple.o
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +21 -0
new file mode 100644
index 00000000000000..48a5e20e07c487
@@ -0,0 +1,339 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ChipWealth CH13726A MIPI-DSI panel driver
+ * Copyright (c) 2024, Teguh Sobirin <[email protected]>.
+ */
+
+#include <linux/backlight.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/regulator/consumer.h>
+
+#include <drm/drm_mipi_dsi.h>
+#include <drm/drm_modes.h>
+#include <drm/drm_panel.h>
+
+#include <video/mipi_display.h>
+
+struct ch13726a_panel {
+     struct drm_panel panel;
Quoted 8 lines

drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c line 27

Quoted 6 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +6 -0
+     struct mipi_dsi_device *dsi;
+     struct regulator_bulk_data supplies[4];
+     struct gpio_desc *reset_gpio;
+     struct ch13726a_desc *desc;
+     enum drm_panel_orientation orientation;
+     bool prepared;

Drop this, it's handled by the panel core now.

Ack.

Quoted 147 lines
Quoted 147 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +146 -0
+};
+
+struct ch13726a_desc {
+     unsigned int width_mm;
+     unsigned int height_mm;
+     unsigned int bpc;
+
+     const struct drm_display_mode *modes;
+     unsigned int num_modes;
+};
+
+static inline struct ch13726a_panel *to_ch13726a_panel(struct drm_panel *panel)
+{
+     return container_of(panel, struct ch13726a_panel, panel);
+}
+
+static void ch13726a_reset(struct ch13726a_panel *ctx)
+{
+     gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+     usleep_range(10000, 11000);
+     gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+     usleep_range(10000, 11000);
+     gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+     usleep_range(10000, 11000);
+}
+
+static int ch13726a_on(struct ch13726a_panel *ctx)
+{
+     struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi };
+
+     ctx->dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+     mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xf0, 0x50);
+     mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xb9, 0x00);
+
+     mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
+
+     mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
+
+     return dsi_ctx.accum_err;
+}
+
+static int ch13726a_disable(struct drm_panel *panel)
+{
+     struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+     struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi };
+
+     ctx->dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+     mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
+     mipi_dsi_msleep(&dsi_ctx, 50);
+     mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
+
+     return dsi_ctx.accum_err;
+}
+
+static int ch13726a_prepare(struct drm_panel *panel)
+{
+     struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+     struct device *dev = &ctx->dsi->dev;
+     int ret;
+
+     if (ctx->prepared)
+             return 0;
+
+     ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+     if (ret < 0) {
+             dev_err(dev, "Failed to enable regulators: %d\n", ret);
+             return ret;
+     }
+
+     ch13726a_reset(ctx);
+
+     ret = ch13726a_on(ctx);
+     if (ret < 0) {
+             dev_err(dev, "Failed to initialize panel: %d\n", ret);
+             gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+             regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+             return ret;
+     }
+
+     msleep(28);
+
+     ctx->prepared = true;
+
+     return 0;
+}
+
+static int ch13726a_unprepare(struct drm_panel *panel)
+{
+     struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+
+     if (!ctx->prepared)
+             return 0;
+
+     gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+     regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+     ctx->prepared = false;
+     return 0;
+}
+
+static const struct drm_display_mode thor_bottom_modes[] = {
+     {
+             /* 120Hz */
+             .clock = (1080 + 28 + 4 + 36) * (1240 + 16 + 4 + 8) * 120 / 1000,
+             .hdisplay = 1080,
+             .hsync_start = 1080 + 28,
+             .hsync_end = 1080 + 28 + 4,
+             .htotal = 1080 + 28 + 4 + 36,
+             .vdisplay = 1240,
+             .vsync_start = 1240 + 16,
+             .vsync_end = 1240 + 16 + 4,
+             .vtotal = 1240 + 16 + 4 + 8,
+     },
+     {
+             /* 60Hz */
+             .clock = (1080 + 28 + 4 + 36) * (1240 + 16 + 4 + 8) * 60 / 1000,
+             .hdisplay = 1080,
+             .hsync_start = 1080 + 28,
+             .hsync_end = 1080 + 28 + 4,
+             .htotal = 1080 + 28 + 4 + 36,
+             .vdisplay = 1240,
+             .vsync_start = 1240 + 16,
+             .vsync_end = 1240 + 16 + 4,
+             .vtotal = 1240 + 16 + 4 + 8,
+     }
+};
+
+static struct ch13726a_desc thor_bottom_desc = {
+     .modes = thor_bottom_modes,
+     .num_modes = ARRAY_SIZE(thor_bottom_modes),
+     .width_mm = 65,
+     .height_mm = 75,
+     .bpc = 8,
+};
+
+static int ch13726a_get_modes(struct drm_panel *panel,
+                                     struct drm_connector *connector)
+{
+     struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+
+     for (uint8_t i = 0; i < ctx->desc->num_modes; i++) {
+             const struct drm_display_mode *m = &ctx->desc->modes[i];
+             struct drm_display_mode *mode;
+
Quoted 8 lines

drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c line 179

Quoted 6 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +6 -0
+             mode = drm_mode_duplicate(connector->dev, m);
+             if (!mode) {
+                     dev_err(&ctx->dsi->dev, "failed to add mode %ux%u@%u\n",
+                             m->hdisplay, m->vdisplay, drm_mode_vrefresh(m));
+                     return -ENOMEM;
+             }

Can you use drm_connector_helper_get_modes_fixed instead ?

Per the description for that function, it only works if there's a single mode. This panel supports two modes, 60hz and 120hz.

Quoted 84 lines
Quoted 84 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +83 -0
+
+             mode->type = DRM_MODE_TYPE_DRIVER;
+             if (i == 0)
+                     mode->type |= DRM_MODE_TYPE_PREFERRED;
+
+             drm_mode_set_name(mode);
+             drm_mode_probed_add(connector, mode);
+     }
+
+     connector->display_info.width_mm = ctx->desc->width_mm;
+     connector->display_info.height_mm = ctx->desc->height_mm;
+     connector->display_info.bpc = ctx->desc->bpc;
+
+     return ctx->desc->num_modes;
+}
+
+static enum drm_panel_orientation ch13726a_get_orientation(struct drm_panel *panel)
+{
+     struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+
+     return ctx->orientation;
+}
+
+static const struct drm_panel_funcs ch13726a_panel_funcs = {
+     .prepare = ch13726a_prepare,
+     .unprepare = ch13726a_unprepare,
+     .disable = ch13726a_disable,
+     .get_modes = ch13726a_get_modes,
+     .get_orientation = ch13726a_get_orientation,
+};
+
+static int ch13726a_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(dsi, brightness);
+     if (ret < 0)
+             return ret;
+
+     dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+     return 0;
+}
+
+static const struct backlight_ops ch13726a_bl_ops = {
+     .update_status = ch13726a_bl_update_status,
+};
+
+static struct backlight_device *
+ch13726a_create_backlight(struct mipi_dsi_device *dsi)
+{
+     struct device *dev = &dsi->dev;
+     const struct backlight_properties props = {
+             .type = BACKLIGHT_RAW,
+             .brightness = 255,
+             .max_brightness = 255,
+     };
+
+     return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+                                           &ch13726a_bl_ops, &props);
+}
+
+static int ch13726a_probe(struct mipi_dsi_device *dsi)
+{
+     struct device *dev = &dsi->dev;
+     struct ch13726a_panel *ctx;
+     int ret;
+
+     ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+     if (!ctx)
+             return -ENOMEM;
+
+     ctx->desc = (struct ch13726a_desc *)of_device_get_match_data(dev);
+     if (!ctx->desc)
+             return -ENODEV;
+
+     ctx->supplies[0].supply = "vdd1v2";
+     ctx->supplies[1].supply = "vddio";
+     ctx->supplies[2].supply = "vdd";
Quoted 8 lines

drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c line 269

Quoted 7 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +7 -0
+     ctx->supplies[3].supply = "avdd";
+
+     ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
+                                   ctx->supplies);
+     if (ret < 0)
+             return dev_err_probe(dev, ret, "Failed to get regulators\n");
+

Can you switch to devm_regulator_bulk_get_const ?

Looks like I can.

Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +15 -0
+     ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
+     if (IS_ERR(ctx->reset_gpio))
+             return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio),
+                                  "Failed to get reset-gpios\n");
+
+     ret = of_drm_get_panel_orientation(dev->of_node, &ctx->orientation);
+     if (ret < 0) {
+             dev_err(dev, "%pOF: failed to get orientation %d\n", dev->of_node, ret);
+             return ret;
+     }
+
+     ctx->dsi = dsi;
+     mipi_dsi_set_drvdata(dsi, ctx);
+
+     dsi->lanes = 4;
Quoted 8 lines

drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c line 290

Quoted 6 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +6 -0
+     dsi->format = MIPI_DSI_FMT_RGB888;
+     dsi->mode_flags = MIPI_DSI_MODE_VIDEO |
+                       MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+     drm_panel_init(&ctx->panel, dev, &ch13726a_panel_funcs,
+                    DRM_MODE_CONNECTOR_DSI);

Please use devm_drm_panel_alloc() instead.

Ack

Quoted 43 lines
Quoted 43 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +42 -0
+     ctx->panel.prepare_prev_first = true;
+
+     ctx->panel.backlight = ch13726a_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);
+
+     ret = mipi_dsi_attach(dsi);
+     if (ret < 0) {
+             dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
+             drm_panel_remove(&ctx->panel);
+             return ret;
+     }
+
+     return 0;
+}
+
+static void ch13726a_remove(struct mipi_dsi_device *dsi)
+{
+     struct ch13726a_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 ch13726a_of_match[] = {
+     { .compatible = "ayntec,thor-panel-bottom", .data = &thor_bottom_desc },
+     { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, ch13726a_of_match);
+
+static struct mipi_dsi_driver ch13726a_driver = {
+     .probe = ch13726a_probe,
+     .remove = ch13726a_remove,
+     .driver = {
+             .name = "panel-ch13726a-amoled",
Quoted 9 lines

drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c line 339

Quoted 8 lines
drivers/gpu/drm/panel/panel-chipwealth-ch13726a.c new file +7 -0
+             .of_match_table = ch13726a_of_match,
+     },
+};
+module_mipi_dsi_driver(ch13726a_driver);
+
+MODULE_DESCRIPTION("DRM driver for CH13726A DSI panels");
+MODULE_LICENSE("GPL");

Aaron