Novatek NT37701 driver / mode-aware drm_panel_prepare
Subsystems (4)
cover Novatek NT37701 driver / mode-aware drm_panel_prepare
I've been working on a driver for the panel in the motorola-dubai[1] phone, which is a 6.55" P-OLED panel based on the NT37701 IC and made by either Tianma or CSOT. Unfortunately there is no info whatsoever on the internet about this panel so I cannot confirm any model number. (Please feel free to suggest a better compatible string.. I'm not sure what the latest convention is for these situations, but I've seen a couple drivers land that don't even mention the panel vendor and use a generic DDIC compatible heh)
The "interesting" thing here is that like most other modern OLEDs this panel supports a lot of refresh rates, and can even change them seamlessly on-the-fly (in downstream dts there are command sequences for this). However upstream currently there hasn't been a driver that needs to send specific DCS commands to configure the mode at all! Most drivers for panels that definitely support various modes have just been listing one mode (e.g. nt37801 only has 120Hz).
(If anyone's wondering about what happens if you skip the commands and just run a mismatched mode: visual glitches, of course.)
Not content with only having no choice of refresh rate at all, I worked on a way to make this work, and it turned out to be pretty easy. The mode can be passed via bridge/panel since it's available there. Adding an alternative prepare callback seemed like the easiest thing to do.
I'm looking for some guidance on getting this to a final patch, if there's any caveats I missed, a better way to pass the mode, etc.
(For the driver, I know I haven't written a binding yet :D)
Thanks,
~val
[1]: https://lore.kernel.org/all/[email protected]/
Val Packett (2):
drm: Introduce drm_panel_prepare_for_mode callback drm/panel: Add driver for Novatek NT37701 based OLED panels
drivers/gpu/drm/bridge/panel.c | 8 +- drivers/gpu/drm/drm_panel.c | 15 +- drivers/gpu/drm/panel/Makefile | 1 + drivers/gpu/drm/panel/panel-novatek-nt37701.c | 532 ++++++++++++++++++ include/drm/drm_panel.h | 12 + 5 files changed, 564 insertions(+), 4 deletions(-) create mode 100644 drivers/gpu/drm/panel/panel-novatek-nt37701.c
Signature · 1 line
2.53.0
RFC PATCH 1/2 drm: Introduce drm_panel_prepare_for_mode callback
Modern OLED panels often need to vary their prepare commands based on the mode being set (resolution and refresh rate). Introduce a new variant of the drm_panel_prepare callback that passes the chosen mode as an argument to allow for this.
--- drivers/gpu/drm/bridge/panel.c | 8 ++++++-- drivers/gpu/drm/drm_panel.c | 15 +++++++++++++-- include/drm/drm_panel.h | 12 ++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/panel.c +6 -2
@@ -116,7 +116,7 @@ static void panel_bridge_atomic_pre_enable(struct drm_bridge *bridge,struct panel_bridge *panel_bridge =drm_bridge_to_panel_bridge (bridge);struct drm_encoder *encoder = bridge->encoder;struct drm_crtc *crtc; -struct drm_crtc_state *old_crtc_state; +struct drm_crtc_state *old_crtc_state, *new_crtc_state; crtc =drm_atomic_get_new_crtc_for_encoder (atomic_state, encoder);if (!crtc)
@@ -126,7 +126,11 @@ static void panel_bridge_atomic_pre_enable(struct drm_bridge *bridge,if (old_crtc_state && old_crtc_state->self_refresh_active)return ; -drm_panel_prepare (panel_bridge->panel); + new_crtc_state =drm_atomic_get_new_crtc_state (atomic_state, crtc); +if (!new_crtc_state) +return ; + +drm_panel_prepare_for_mode (panel_bridge->panel, &new_crtc_state->mode); } static void panel_bridge_atomic_enable(struct drm_bridge *bridge,
drivers/gpu/drm/drm_panel.c +13 -2
@@ -112,6 +112,13 @@ EXPORT_SYMBOL(drm_panel_remove);* drm_panel_disable() afterwards. */ void drm_panel_prepare (struct drm_panel *panel) +{ +drm_panel_prepare_for_mode (panel,NULL ); +} +EXPORT_SYMBOL (drm_panel_prepare); + +void drm_panel_prepare_for_mode (struct drm_panel *panel, +struct drm_display_mode *mode) {struct drm_panel_follower *follower;int ret;
@@ -126,7 +133,11 @@ void drm_panel_prepare(struct drm_panel *panel)mutex_lock (&panel->follower_lock); -if (panel->funcs && panel->funcs->prepare) { +if (panel->funcs && panel->funcs->prepare_for_mode && mode) { + ret = panel->funcs->prepare_for_mode (panel, mode); +if (ret <0 ) + goto exit; + }else if (panel->funcs && panel->funcs->prepare) { ret = panel->funcs->prepare (panel);if (ret <0 ) goto exit;
@@ -146,7 +157,7 @@ void drm_panel_prepare(struct drm_panel *panel) exit:mutex_unlock (&panel->follower_lock); } -EXPORT_SYMBOL (drm_panel_prepare); +EXPORT_SYMBOL (drm_panel_prepare_for_mode);/** * drm_panel_unprepare - power off a panel
include/drm/drm_panel.h +12 -0
@@ -80,6 +80,16 @@ struct drm_panel_funcs {*/ int (*prepare)(struct drm_panel *panel); +/** +* @prepare_for_mode: +* +* Turn on panel and perform set up, with awareness of the mode being set. +* +* This function is optional. +*/ +int (*prepare_for_mode)(struct drm_panel *panel, +struct drm_display_mode *mode); +/** * @enable: *
@@ -331,6 +341,8 @@ void drm_panel_add(struct drm_panel *panel);void drm_panel_remove (struct drm_panel *panel);void drm_panel_prepare (struct drm_panel *panel); +void drm_panel_prepare_for_mode (struct drm_panel *panel, +struct drm_display_mode *mode);void drm_panel_unprepare (struct drm_panel *panel);void drm_panel_enable (struct drm_panel *panel);
Signature · 1 line
2.53.0
Re: [RFC PATCH 1/2] drm: Introduce drm_panel_prepare_for_mode callback
Quoted 5 lines · Val Packett
Modern OLED panels often need to vary their prepare commands based on the mode being set (resolution and refresh rate). Introduce a new variant of the
drm_panel_preparecallback that passes the chosen mode as an argument to allow for this.
Quoted 7 lines
Signed-off-by Val Packett <[email protected]>--- drivers/gpu/drm/bridge/panel.c | 8 ++++++-- drivers/gpu/drm/drm_panel.c | 15 +++++++++++++-- include/drm/drm_panel.h | 12 ++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-)
A (somewhat) better approach would be to let add .atomic_foo callbacks, which would receive drm_atomic_state instance. See the discussion around [1].
[1] https://lore.kernel.org/dri-devel/nfc6ih43gjpi5u67fpkkxgwwygv53grdldq7tfp5iiukrkiy2u@53fsrtezzkyt/
Signature · 2 lines
With best wishes Dmitry
Neil Armstrong
maintainerRe: [RFC PATCH 1/2] drm: Introduce drm_panel_prepare_for_mode callback
Quoted 14 lines · Dmitry Baryshkov
Quoted 5 lines · Val Packett
Modern OLED panels often need to vary their prepare commands based on the mode being set (resolution and refresh rate). Introduce a new variant of the
drm_panel_preparecallback that passes the chosen mode as an argument to allow for this.Quoted 7 lines
Signed-off-by Val Packett <[email protected]>--- drivers/gpu/drm/bridge/panel.c | 8 ++++++-- drivers/gpu/drm/drm_panel.c | 15 +++++++++++++-- include/drm/drm_panel.h | 12 ++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-)
Quoted 6 lines
A (somewhat) better approach would be to let add .atomic_foo callbacks, which would receive
drm_atomic_stateinstance. See the discussion around [1].[1] https://lore.kernel.org/dri-devel/nfc6ih43gjpi5u67fpkkxgwwygv53grdldq7tfp5iiukrkiy2u@53fsrtezzkyt/
I agree, the plan to add a new atomic ops if much better.
Neil
RFC PATCH 2/2 drm/panel: Add driver for Novatek NT37701 based OLED panels
In reply to Val PackettAdd a driver for panels with the NT37701 DDIC, starting with the Tianma panel (unknown model) used in the Motorola Edge 30 (dubai) smartphone.
--- drivers/gpu/drm/panel/Makefile | 1 + drivers/gpu/drm/panel/panel-novatek-nt37701.c | 532 ++++++++++++++++++ 2 files changed, 533 insertions(+) create mode 100644 drivers/gpu/drm/panel/panel-novatek-nt37701.c
drivers/gpu/drm/panel/Makefile +1 -0
@@ -60,6 +60,7 @@ obj-$(CONFIG_DRM_PANEL_NOVATEK_NT36523) += panel-novatek-nt36523.o obj-$(CONFIG_DRM_PANEL_NOVATEK_NT36672A) += panel-novatek-nt36672a.o obj-$(CONFIG_DRM_PANEL_NOVATEK_NT36672E) += panel-novatek-nt36672e.o obj-$(CONFIG_DRM_PANEL_NOVATEK_NT37700F) += panel-novatek-nt37700f.o +obj-m += panel-novatek-nt37701.o obj-$(CONFIG_DRM_PANEL_NOVATEK_NT37801) += panel-novatek-nt37801.o obj-$(CONFIG_DRM_PANEL_NOVATEK_NT39016) += panel-novatek-nt39016.o obj-$(CONFIG_DRM_PANEL_MANTIX_MLAF057WE51) += panel-mantix-mlaf057we51.o
drivers/gpu/drm/panel/panel-novatek-nt37701.c new file +532 -0
532 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [RFC PATCH 2/2] drm/panel: Add driver for Novatek NT37701 based OLED panels
Quoted 158 lines · Val Packett
Add a driver for panels with the NT37701 DDIC, starting with the Tianma panel (unknown model) used in the Motorola Edge 30 (dubai) smartphone.
Signed-off-by Val Packett <[email protected]>--- drivers/gpu/drm/panel/Makefile | 1 + drivers/gpu/drm/panel/panel-novatek-nt37701.c | 532 ++++++++++++++++++ 2 files changed, 533 insertions(+) create mode 100644 drivers/gpu/drm/panel/panel-novatek-nt37701.cdrivers/gpu/drm/panel/Makefile +1
-0@@ -60,6 +60,7 @@ obj-$(CONFIG_DRM_PANEL_NOVATEK_NT36523) += panel-novatek-nt36523.o obj-$(CONFIG_DRM_PANEL_NOVATEK_NT36672A) += panel-novatek-nt36672a.o obj-$(CONFIG_DRM_PANEL_NOVATEK_NT36672E) += panel-novatek-nt36672e.o obj-$(CONFIG_DRM_PANEL_NOVATEK_NT37700F) += panel-novatek-nt37700f.o +obj-m += panel-novatek-nt37701.o obj-$(CONFIG_DRM_PANEL_NOVATEK_NT37801) += panel-novatek-nt37801.o obj-$(CONFIG_DRM_PANEL_NOVATEK_NT39016) += panel-novatek-nt39016.o obj-$(CONFIG_DRM_PANEL_MANTIX_MLAF057WE51) += panel-mantix-mlaf057we51.odrivers/gpu/drm/panel/panel-novatek-nt37701.c new file +130
-0@@ -0,0 +1,532 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2026, The Linux Foundation. All rights reserved. +* Generated with linux-mdss-dsi-panel-driver-generator from vendor device tree: +* Copyright (c) 2013, The Linux Foundation. All rights reserved. +*/ + +#include <linux/backlight.h> +#include <linux/delay.h> +#include <linux/gpio/consumer.h> +#include <linux/module.h> +#include <linux/regulator/consumer.h> +#include <linux/of.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> + +enum nt37701_mode_idx { +MODE_144HZ , +MODE_120HZ , +MODE_90HZ , +MODE_60HZ , +MODE_48HZ , +}; + +static const struct drm_display_mode nt37701_panel_modes[5 ]; + +struct nt37701_panel { +struct drm_panel panel; +struct mipi_dsi_device *dsi; +struct drm_dsc_config dsc; +struct regulator *supply; +struct gpio_desc *reset_gpio; +}; + +static inline +struct nt37701_panel *to_nt37701_panel (struct drm_panel *panel) +{ + return container_of(panel, struct nt37701_panel, panel); +} + +static void nt37701_panel_reset (struct nt37701_panel *ctx) +{ +gpiod_set_value_cansleep (ctx->reset_gpio,1 ); +usleep_range (1000 ,2000 ); +gpiod_set_value_cansleep (ctx->reset_gpio,0 ); +usleep_range (10000 ,11000 ); +} + +#define nt37701_panel_switch_page (ctx, page) \ + mipi_dsi_dcs_write_seq_multi((ctx), 0xf0, 0x55, 0xaa, 0x52, 0x08, (page)) + +static int nt37701_panel_on (struct nt37701_panel *ctx, +struct drm_display_mode *mode) +{ +struct mipi_dsi_device *dsi = ctx->dsi; +struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi }; + + dsi->mode_flags |=MIPI_DSI_MODE_LPM ; + +nt37701_panel_switch_page (&dsi_ctx,0x00 ); +/* Voltage */ +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x6f ,0x06 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xb5 ,0x00 ,0x18 ,0x4f ); + +nt37701_panel_switch_page (&dsi_ctx,0x00 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xb2 ,0x11 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x6f ,0x0f ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xb2 , +0x60 ,0x50 ,0x66 ,0x91 ,0x86 ,0x91 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xb3 , +0x00 ,0x08 ,0x01 ,0x5f ,0x01 ,0x5f ,0x02 , +0xa4 ,0x02 ,0xa4 ,0x03 ,0xbb ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x6f ,0x0c ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xb3 , +0x03 ,0xbb ,0x05 ,0x2f ,0x05 ,0x2f ,0x06 , +0x91 ,0x06 ,0x91 ,0x06 ,0x92 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x6f ,0x18 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xb3 , +0x06 ,0x92 ,0x0a ,0x2f ,0x0a ,0x2f ,0x0d , +0xb9 ,0x0d ,0xb9 ,0x0f ,0xff ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x58 ,0x00 ); + +nt37701_panel_switch_page (&dsi_ctx,0x00 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x6f ,0x08 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xc3 ,0x04 ); + +nt37701_panel_switch_page (&dsi_ctx,0x03 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xbc ,0x11 ,0x00 ,0x09 ,0x51 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x6f ,0x04 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xbc , +0x00 ,0x09 ,0x51 ,0x00 ,0x09 ,0x51 ,0x00 , +0x0b ,0x41 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x6f ,0x0d ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xbc ,0x00 ,0x11 ,0x51 ); + +nt37701_panel_switch_page (&dsi_ctx,0x00 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xc6 , +0x66 ,0x66 ,0x66 ,0x66 ,0x66 ,0x66 ,0x66 , +0x66 ,0x66 ,0x66 ,0x66 ,0x66 ); + +nt37701_panel_switch_page (&dsi_ctx,0x00 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x6f ,0x1c ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xc0 , +0x15 ,0x0a ,0x38 ,0x27 ,0x49 ); +/* DSC */ +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x03 ,0x01 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x90 ,0x01 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x91 , +0xab ,0x28 ,0x00 ,0x0c ,0xc2 ,0x00 ,0x03 , +0x1c ,0x01 ,0x7e ,0x00 ,0x0f ,0x08 ,0xbb , +0x04 ,0x3d ,0x10 ,0xf0 ); + +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,MIPI_DCS_WRITE_MEMORY_START , +0x00 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x6f ,0x01 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x88 ,0x02 ,0x1c ,0x08 ,0x73 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x5f ,0x00 ); +mipi_dsi_dcs_set_display_brightness_multi (&dsi_ctx,0x0000 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,MIPI_DCS_WRITE_CONTROL_DISPLAY , +0x20 ); +mipi_dsi_dcs_set_tear_on_multi (&dsi_ctx,MIPI_DSI_DCS_TEAR_MODE_VBLANK ); +mipi_dsi_dcs_set_column_address_multi (&dsi_ctx,0x0000 ,0x0437 ); +mipi_dsi_dcs_set_page_address_multi (&dsi_ctx,0x0000 ,0x095f );
drivers/gpu/drm/panel/panel-novatek-nt37701.c line 140
Quoted 10 lines
drivers/gpu/drm/panel/panel-novatek-nt37701.c new file +10
-0+if (mode->clock == nt37701_panel_modes[MODE_144HZ ].clock) +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x2f ,0x04 ); +else if (mode->clock == nt37701_panel_modes[MODE_120HZ ].clock) +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x2f ,0x02 ); +else if (mode->clock == nt37701_panel_modes[MODE_90HZ ].clock) +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x2f ,0x07 ); +else if (mode->clock == nt37701_panel_modes[MODE_60HZ ].clock) +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x2f ,0x03 ); +else +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0x2f ,0x08 );
This should be coming through the drm_atomic_state for the CRTC used by this panel. Most of the plumbing is already there, panel bridge needs to pass atomic state to the drm_panel functions. Note, the bridge has a reference to the encoder, so it can retrieve CRTC state. Panel functions would need to get drm_connector so that they can perform the same lookup. Once you get drm_crtc_state::mode, you can perform lookups here.
It's a longer path than the one you have RFC'd here, but I think, it is a proper way to go.
Quoted 7 lines
drivers/gpu/drm/panel/panel-novatek-nt37701.c new file +7
-0+nt37701_panel_switch_page (&dsi_ctx,0x08 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xe1 , +0x00 ,0x03 ,0x03 ,0x03 ,0x00 ); +mipi_dsi_dcs_write_seq_multi (&dsi_ctx,0xe2 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 );
Signature · 2 lines
With best wishes Dmitry