Skip to contentSkip to conversation

Add support for Visionox R66451 AMOLED DSI panel

PATCH In review Jessica Zhang 5 participants 26 messages May 16, 2023 – May 31, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Add support for Visionox R66451 AMOLED DSI panel

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The driver will come with display compression (DSC v1.2) enabled by default.

---
Jessica Zhang (2):
dt-bindings: display: panel: Add Visionox R66451 AMOLED DSI panel bindings drm/panel: Add driver for Visionox r66451 panel

 .../bindings/display/panel/visionox,r66451.yaml    |  59 +++
 drivers/gpu/drm/panel/Kconfig                      |   8 +
 drivers/gpu/drm/panel/Makefile                     |   1 +
 drivers/gpu/drm/panel/panel-visionox-r66451.c      | 395 +++++++++++++++++++++
 4 files changed, 463 insertions(+)

---
base-commit: a5abc0900af0cfb1b8093200a265d2791864f26b
change-id: 20230516-b4-r66451-panel-driver-bf04b5fb3d52

Best regards,

Signature · 1 line
Jessica Zhang <[email protected]>
#1 lore raw

PATCH 1/2 dt-bindings: display: panel: Add Visionox R66451 AMOLED DSI panel bindings

Document the 1080x2340 Visionox R66451 AMOLED DSI panel bindings

---
 .../bindings/display/panel/visionox,r66451.yaml    | 59 ++++++++++++++++++++++
 1 file changed, 59 insertions(+)
Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml new file +59 -0
new file mode 100644
index 000000000000..6ba323683921
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/panel/visionox,r66451.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Visionox R66451 AMOLED DSI Panel
+
+maintainers:
+  - Jessica Zhang <[email protected]>
+
+allOf:
+  - $ref: panel-common.yaml#
+
+properties:
+  compatible:
+    const: visionox,r66451
+
+  reg:
+    maxItems: 1
+    description: DSI virtual channel
+
+  vddio-supply: true
+  vdd-supply: true
+  port: true
+  reset-gpios: true
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - vddio-supply
+  - vdd-supply
+  - reset-gpios
+  - port
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    dsi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        panel@0 {
+            compatible = "visionox,r66451";
+            reg = <0>;
+            vddio-supply = <&vreg_l12c_1p8>;
+            vdd-supply = <&vreg_l13c_3p0>;
+
+            reset-gpios = <&tlmm 24 GPIO_ACTIVE_LOW>;
+
+            port {
+                panel0_in: endpoint {
+                    remote-endpoint = <&dsi0_out>;
+                };
+            };
+        };
+    };
+...
Signature · 1 line
2.40.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] dt-bindings: display: panel: Add Visionox R66451 AMOLED DSI panel bindings

Quoted 6 lines · Jessica Zhang

Document the 1080x2340 Visionox R66451 AMOLED DSI panel bindings

---
 .../bindings/display/panel/visionox,r66451.yaml    | 59 ++++++++++++++++++++++
 1 file changed, 59 insertions(+)

If there is going to be new version:
A nit, subject: drop second/last, redundant "bindings". The "dt-bindings" prefix is already stating that these are bindings.

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH 1/2] dt-bindings: display: panel: Add Visionox R66451 AMOLED DSI panel bindings

In reply to Jessica Zhang
Quoted 29 lines · Jessica Zhang

Document the 1080x2340 Visionox R66451 AMOLED DSI panel bindings

---
 .../bindings/display/panel/visionox,r66451.yaml    | 59 ++++++++++++++++++++++
 1 file changed, 59 insertions(+)
Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml new file +16 -0
new file mode 100644
index 000000000000..6ba323683921
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/panel/visionox,r66451.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Visionox R66451 AMOLED DSI Panel
+
+maintainers:
+  - Jessica Zhang <[email protected]>
+
+allOf:
+  - $ref: panel-common.yaml#
+
+properties:
+  compatible:

Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml line 26

Quoted 10 lines
Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml new file +10 -0
+    const: visionox,r66451
+
+  reg:
+    maxItems: 1
+    description: DSI virtual channel
+
+  vddio-supply: true
+  vdd-supply: true
+  port: true
+  reset-gpios: true

Normally for cmd-mode panels there is also a disp-te pin which is optionally registered in dsi_host.c as GPIOD_IN, but on **ALL** my Sony phones this breaks vsync (as in: mdp5 stops receiving the interrupt, but we can see disp-te in /proc/interrupts then).

- Marijn

Quoted 36 lines
Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml new file +32 -0
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - vddio-supply
+  - vdd-supply
+  - reset-gpios
+  - port
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    dsi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        panel@0 {
+            compatible = "visionox,r66451";
+            reg = <0>;
+            vddio-supply = <&vreg_l12c_1p8>;
+            vdd-supply = <&vreg_l13c_3p0>;
+
+            reset-gpios = <&tlmm 24 GPIO_ACTIVE_LOW>;
+
+            port {
+                panel0_in: endpoint {
+                    remote-endpoint = <&dsi0_out>;
+                };
+            };
+        };
+    };
+...
Signature · 2 lines
-- 
2.40.1
maintainer
#4 lore raw

Re: [PATCH 1/2] dt-bindings: display: panel: Add Visionox R66451 AMOLED DSI panel bindings

Quoted 37 lines · Marijn Suijten
Quoted 36 lines · Jessica Zhang

Document the 1080x2340 Visionox R66451 AMOLED DSI panel bindings

---
  .../bindings/display/panel/visionox,r66451.yaml    | 59 ++++++++++++++++++++++
  1 file changed, 59 insertions(+)
Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml new file +23 -0
new file mode 100644
index 000000000000..6ba323683921
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/panel/visionox,r66451.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Visionox R66451 AMOLED DSI Panel
+
+maintainers:
+  - Jessica Zhang <[email protected]>
+
+allOf:
+  - $ref: panel-common.yaml#
+
+properties:
+  compatible:
+    const: visionox,r66451
+
+  reg:
+    maxItems: 1
+    description: DSI virtual channel
+
+  vddio-supply: true
Quoted 8 lines

Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml line 26

Quoted 3 lines
Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml new file +3 -0
+  vdd-supply: true
+  port: true
+  reset-gpios: true

Normally for cmd-mode panels there is also a disp-te pin which is optionally registered in dsi_host.c as GPIOD_IN, but on **ALL** my Sony phones this breaks vsync (as in: mdp5 stops receiving the interrupt, but we can see disp-te in /proc/interrupts then).

Describing it as a gpio is wrong, it should be described as a pinctrl state instead.

Neil

Quoted 39 lines

- Marijn

Quoted 36 lines
Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml new file +32 -0
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - vddio-supply
+  - vdd-supply
+  - reset-gpios
+  - port
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    dsi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        panel@0 {
+            compatible = "visionox,r66451";
+            reg = <0>;
+            vddio-supply = <&vreg_l12c_1p8>;
+            vdd-supply = <&vreg_l13c_3p0>;
+
+            reset-gpios = <&tlmm 24 GPIO_ACTIVE_LOW>;
+
+            port {
+                panel0_in: endpoint {
+                    remote-endpoint = <&dsi0_out>;
+                };
+            };
+        };
+    };
+...
Signature · 2 lines
-- 
2.40.1
#5 lore raw

Re: [PATCH 1/2] dt-bindings: display: panel: Add Visionox R66451 AMOLED DSI panel bindings

Quoted 47 lines · Neil Armstrong
Quoted 37 lines · Marijn Suijten
Quoted 36 lines · Jessica Zhang

Document the 1080x2340 Visionox R66451 AMOLED DSI panel bindings

---
  .../bindings/display/panel/visionox,r66451.yaml    | 59 ++++++++++++++++++++++
  1 file changed, 59 insertions(+)
Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml new file +23 -0
new file mode 100644
index 000000000000..6ba323683921
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/panel/visionox,r66451.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Visionox R66451 AMOLED DSI Panel
+
+maintainers:
+  - Jessica Zhang <[email protected]>
+
+allOf:
+  - $ref: panel-common.yaml#
+
+properties:
+  compatible:
+    const: visionox,r66451
+
+  reg:
+    maxItems: 1
+    description: DSI virtual channel
+
+  vddio-supply: true
Quoted 8 lines

Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml line 26

Quoted 3 lines
Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml new file +3 -0
+  vdd-supply: true
+  port: true
+  reset-gpios: true

Normally for cmd-mode panels there is also a disp-te pin which is optionally registered in dsi_host.c as GPIOD_IN, but on **ALL** my Sony phones this breaks vsync (as in: mdp5 stops receiving the interrupt, but we can see disp-te in /proc/interrupts then).

Quoted 1 line

Describing it as a gpio is wrong, it should be described as a pinctrl state instead.

We defined both in our DTS, what weirdness does it cause when then requested using GPIOD_IN? It'd still be beneficial to see the vsync interrupt raise in /proc/interrupts (but it's just a waste of CPU cycles OTOH, this is all handled in the MDP hardware after all, so it's not something I'd like to enable by default).

Anyway, this is what we ended up doing to "fix" the bug (only bias the pin via pinctrl, omit the disp-te DTS property). Thanks for confirming!

- Marijn

Quoted 2 lines

Neil

<snip>

maintainer
#6 lore raw

Re: [PATCH 1/2] dt-bindings: display: panel: Add Visionox R66451 AMOLED DSI panel bindings

Quoted 48 lines · Marijn Suijten
Quoted 47 lines · Neil Armstrong
Quoted 45 lines · Marijn Suijten
Quoted 29 lines · Jessica Zhang

Document the 1080x2340 Visionox R66451 AMOLED DSI panel bindings

---
   .../bindings/display/panel/visionox,r66451.yaml    | 59 ++++++++++++++++++++++
   1 file changed, 59 insertions(+)
Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml new file +16 -0
new file mode 100644
index 000000000000..6ba323683921
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/panel/visionox,r66451.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Visionox R66451 AMOLED DSI Panel
+
+maintainers:
+  - Jessica Zhang <[email protected]>
+
+allOf:
+  - $ref: panel-common.yaml#
+
+properties:
+  compatible:

Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml line 26

Quoted 10 lines
Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml new file +10 -0
+    const: visionox,r66451
+
+  reg:
+    maxItems: 1
+    description: DSI virtual channel
+
+  vddio-supply: true
+  vdd-supply: true
+  port: true
+  reset-gpios: true

Normally for cmd-mode panels there is also a disp-te pin which is optionally registered in dsi_host.c as GPIOD_IN, but on **ALL** my Sony phones this breaks vsync (as in: mdp5 stops receiving the interrupt, but we can see disp-te in /proc/interrupts then).

Quoted 7 lines
Quoted 1 line

Describing it as a gpio is wrong, it should be described as a pinctrl state instead.

We defined both in our DTS, what weirdness does it cause when then requested using GPIOD_IN? It'd still be beneficial to see the vsync interrupt raise in /proc/interrupts (but it's just a waste of CPU cycles OTOH, this is all handled in the MDP hardware after all, so it's not something I'd like to enable by default).

Sure, but it's a sw hack, the pin has a TE function which directly goes to the DSI logic, claiming it as a GPIO will set it as GPIO function.

On some platforms, PINMUX is only on output and input is always directed to all HW blocks, seems it's not the case here !

Quoted 10 lines

Anyway, this is what we ended up doing to "fix" the bug (only bias the pin via pinctrl, omit the disp-te DTS property). Thanks for confirming!

- Marijn

Quoted 2 lines

Neil

<snip>

#7 lore raw

Re: [PATCH 1/2] dt-bindings: display: panel: Add Visionox R66451 AMOLED DSI panel bindings

Quoted 57 lines · Neil Armstrong
Quoted 48 lines · Marijn Suijten
Quoted 47 lines · Neil Armstrong
Quoted 45 lines · Marijn Suijten
Quoted 29 lines · Jessica Zhang

Document the 1080x2340 Visionox R66451 AMOLED DSI panel bindings

---
   .../bindings/display/panel/visionox,r66451.yaml    | 59 ++++++++++++++++++++++
   1 file changed, 59 insertions(+)
Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml new file +16 -0
new file mode 100644
index 000000000000..6ba323683921
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/panel/visionox,r66451.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Visionox R66451 AMOLED DSI Panel
+
+maintainers:
+  - Jessica Zhang <[email protected]>
+
+allOf:
+  - $ref: panel-common.yaml#
+
+properties:
+  compatible:

Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml line 26

Quoted 10 lines
Documentation/devicetree/bindings/display/panel/visionox,r66451.yaml new file +10 -0
+    const: visionox,r66451
+
+  reg:
+    maxItems: 1
+    description: DSI virtual channel
+
+  vddio-supply: true
+  vdd-supply: true
+  port: true
+  reset-gpios: true

Normally for cmd-mode panels there is also a disp-te pin which is optionally registered in dsi_host.c as GPIOD_IN, but on **ALL** my Sony phones this breaks vsync (as in: mdp5 stops receiving the interrupt, but we can see disp-te in /proc/interrupts then).

Quoted 7 lines
Quoted 1 line

Describing it as a gpio is wrong, it should be described as a pinctrl state instead.

We defined both in our DTS, what weirdness does it cause when then requested using GPIOD_IN? It'd still be beneficial to see the vsync interrupt raise in /proc/interrupts (but it's just a waste of CPU cycles OTOH, this is all handled in the MDP hardware after all, so it's not something I'd like to enable by default).

Quoted 5 lines

Sure, but it's a sw hack, the pin has a TE function which directly goes to the DSI logic, claiming it as a GPIO will set it as GPIO function.

On some platforms, PINMUX is only on output and input is always directed to all HW blocks, seems it's not the case here !

Ah that makes total sense! The PINGROUP() is only passed this mdp_vsync function but internally provides the gpio function as well, which it'd have to use to read it as GPIO from the SoC-side: and this indeed seems to "disconnect" that pin from the MDP HW block. Thanks for mentioning this, I totally overlooked it.

Should we document/clarify this in any way, or perhaps remove the disp-te handling altogether (dsi_host.c doesn't use this interrupt for anything, though we could leave it for debug purposes if describing / wrapping it more clearly). Downstream also sets this pin in DT but doesn't ever request a GPIO/IRQ on it, afaik.

- Marijn

Quoted 10 lines
Quoted 9 lines

Anyway, this is what we ended up doing to "fix" the bug (only bias the pin via pinctrl, omit the disp-te DTS property). Thanks for confirming!

- Marijn

Quoted 2 lines

Neil

<snip>

#8 lore raw

PATCH 2/2 drm/panel: Add driver for Visionox r66451 panel

In reply to Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
 drivers/gpu/drm/panel/Kconfig                 |   8 +
 drivers/gpu/drm/panel/Makefile                |   1 +
 drivers/gpu/drm/panel/panel-visionox-r66451.c | 395 ++++++++++++++++++++++++++
 3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +8 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130
 	  Say Y here if you want to enable support for Visionox
 	  VTDR6130 1080x2400 AMOLED DSI panel.
 
+config DRM_PANEL_VISIONOX_R66451
+	tristate "Visionox R66451"
+	depends on OF
+	depends on DRM_MIPI_DSI
+	help
+	  Say Y here if you want to enable support for Visionox
+	  R66451 1080x2340 AMOLED DSI panel.
+
 config DRM_PANEL_WIDECHIPS_WS2401
 	tristate "Widechips WS2401 DPI panel driver"
 	depends on SPI && GPIOLIB
drivers/gpu/drm/panel/Makefile +1 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += panel-tpo-tpg110.o
 obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o
 obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o
 obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o
+obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o
 obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o
 obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +395 -0

395 lines not on this page · raw message

Signature · 1 line
2.40.1
#9 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

Quoted 145 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
  drivers/gpu/drm/panel/Kconfig                 |   8 +
  drivers/gpu/drm/panel/Makefile                |   1 +
  drivers/gpu/drm/panel/panel-visionox-r66451.c | 395 ++++++++++++++++++++++++++
  3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +8 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130
  	  Say Y here if you want to enable support for Visionox
  	  VTDR6130 1080x2400 AMOLED DSI panel.
 
+config DRM_PANEL_VISIONOX_R66451
+	tristate "Visionox R66451"
+	depends on OF
+	depends on DRM_MIPI_DSI
+	help
+	  Say Y here if you want to enable support for Visionox
+	  R66451 1080x2340 AMOLED DSI panel.
+
  config DRM_PANEL_WIDECHIPS_WS2401
  	tristate "Widechips WS2401 DPI panel driver"
  	depends on SPI && GPIOLIB
drivers/gpu/drm/panel/Makefile +1 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += panel-tpo-tpg110.o
  obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o
  obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o
  obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o
+obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o
  obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o
  obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +97 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+	struct drm_panel panel;
+	struct mipi_dsi_device *dsi;
+	struct gpio_desc *reset_gpio;
+	struct regulator_bulk_data supplies[2];
+	bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct drm_panel *panel)
+{
+	return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+	gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+	usleep_range(10000, 10100);
+	gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+	usleep_range(10000, 10100);
+	gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+	usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	struct device *dev = &dsi->dev;
+	int ret;
+
+	dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xc2,
+			       0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
+			       0x09, 0x3c);
+	mipi_dsi_dcs_write_seq(dsi, 0xd7,
+			       0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+			       0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+			       0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+	mipi_dsi_dcs_write_seq(dsi, 0xde,
+			       0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+			       0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02, 0x00, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+	mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+	mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xc4,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32);
+	mipi_dsi_dcs_write_seq(dsi, 0xcf,
+			       0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
+			       0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+			       0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+	mipi_dsi_dcs_write_seq(dsi, 0xd3,
+			       0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07,
+			       0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0,
+			       0x3c, 0x9c);
+	mipi_dsi_dcs_write_seq(dsi, 0xd7,
+			       0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+			       0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+			       0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+	mipi_dsi_dcs_write_seq(dsi, 0xd8,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a,
+			       0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
+			       0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+	mipi_dsi_dcs_write_seq(dsi, 0xdf,
+			       0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00,
+			       0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+	mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00, 0x39, 0x04, 0x09, 0x34);
+	mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);

drivers/gpu/drm/panel/panel-visionox-r66451.c line 107

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+	mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+	mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+	mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01);
+	mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+	mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+	mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+	mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
+	mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x04, 0x37);

Please use mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1);

drivers/gpu/drm/panel/panel-visionox-r66451.c line 108

Quoted 1 line
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +1 -0
+	mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00, 0x09, 0x23);

mipi_dsi_dcs_set_page_address(dsi, 0, 2340 - 1);

drivers/gpu/drm/panel/panel-visionox-r66451.c line 117

Quoted 9 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -0
+
+	ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+		return ret;
+	}
+	msleep(120);
+
+	ret = mipi_dsi_dcs_set_display_on(dsi);

Should the mipi_dsi_dcs_set_display_on() (and maybe exit sleep mode) be a a part of _enable()? Correspondingly _off should IMO be a part of _disable callback().

drivers/gpu/drm/panel/panel-visionox-r66451.c line 122

Quoted 5 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+	if (ret < 0) {
+		dev_err(dev, "Failed on set display on: %d\n", ret);
+		return ret;
+	}
+	msleep(20);

Do we need to add here the following line?

dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

Quoted 79 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +79 -0
+
+	return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	struct device *dev = &dsi->dev;
+	int ret;
+
+	dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+	ret = mipi_dsi_dcs_set_display_off(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed to set display off: %d\n", ret);
+		return ret;
+	}
+	msleep(20);
+
+	ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+		return ret;
+	}
+	msleep(120);
+
+	return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(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)
+		return ret;
+
+	visionox_r66451_reset(ctx);
+
+	ret = visionox_r66451_on(ctx);
+	if (ret < 0) {
+		dev_err(dev, "Failed to initialize panel: %d\n", ret);
+		gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+		regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+		return ret;
+	}
+
+	ctx->prepared = true;
+	return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+	struct device *dev = &ctx->dsi->dev;
+	int ret;
+
+	if (!ctx->prepared)
+		return 0;
+
+	ret = visionox_r66451_off(ctx);
+	if (ret < 0)
+		dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+	gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+	regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+	ctx->prepared = false;
+	return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+	.clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,

drivers/gpu/drm/panel/panel-visionox-r66451.c line 211

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+	.hdisplay = 1080,
+	.hsync_start = 1080 + 95,
+	.hsync_end = 1080 + 95 + 1,
+	.htotal = 1080 + 95 + 1 + 40,
+	.vdisplay = 2340,
+	.vsync_start = 2340 + 25,
+	.vsync_end = 2340 + 25 + 1,
+	.vtotal = 2340 + 25 + 1 + 4,
+	.width_mm = 0,
+	.height_mm = 0,

Please provide real values here.

Quoted 39 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +39 -0
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	struct drm_dsc_picture_parameter_set pps;
+	int ret;
+
+	if (ctx->enabled)
+		return 0;
+
+	if (!dsi->dsc) {
+		dev_err(&dsi->dev, "DSC not attached to DSI\n");
+		return -ENODEV;
+	}
+
+	drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+	ret = mipi_dsi_picture_parameter_set(dsi, &pps);
+
+	ctx->enabled = true;
+
+	return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+	ctx->enabled = false;
+
+	return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+				    struct drm_connector *connector)
+{
+	struct drm_display_mode *mode;
+

drivers/gpu/drm/panel/panel-visionox-r66451.c line 260

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+	mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+	if (!mode)
+		return -ENOMEM;
+
+	drm_mode_set_name(mode);
+
+	mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+	connector->display_info.width_mm = mode->width_mm;
+	connector->display_info.height_mm = mode->height_mm;
+	drm_mode_probed_add(connector, mode);

Can we use drm_connector_helper_get_modes_fixed() instead?

Quoted 8 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +8 -0
+
+	return 1;
+}
+
+static const struct drm_panel_funcs visionox_r66451_funcs = {
+	.prepare = visionox_r66451_prepare,
+	.unprepare = visionox_r66451_unprepare,
+	.get_modes = visionox_r66451_get_modes,

drivers/gpu/drm/panel/panel-visionox-r66451.c line 278

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+	.enable = visionox_r66451_enable,
+	.disable = visionox_r66451_disable,
+};
+
+static int visionox_r66451_bl_update_status(struct backlight_device *bl)
+{
+	struct mipi_dsi_device *dsi = bl_get_data(bl);
+	u16 brightness = backlight_get_brightness(bl);
+
+	return mipi_dsi_dcs_set_display_brightness(dsi, cpu_to_le16(brightness));

mipi_dsi_dcs_set_display_brightness() already converts the brightness, so you don't need cpu_to_le16 here.

Quoted 118 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +117 -0
+}
+
+static const struct backlight_ops visionox_r66451_bl_ops = {
+	.update_status = visionox_r66451_bl_update_status,
+};
+
+static struct backlight_device *
+visionox_r66451_create_backlight(struct mipi_dsi_device *dsi)
+{
+	struct device *dev = &dsi->dev;
+	const struct backlight_properties props = {
+		.type = BACKLIGHT_RAW,
+		.brightness = 255,
+		.max_brightness = 4095,
+	};
+
+	return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+					      &visionox_r66451_bl_ops, &props);
+}
+
+static int visionox_r66451_probe(struct mipi_dsi_device *dsi)
+{
+	struct device *dev = &dsi->dev;
+	struct visionox_r66451 *ctx;
+	struct drm_dsc_config *dsc;
+	int ret = 0;
+
+	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return -ENOMEM;
+
+	dsc = devm_kzalloc(dev, sizeof(*dsc), GFP_KERNEL);
+	if (!dsc)
+		return -ENOMEM;
+
+	/* Set DSC params */
+	dsc->dsc_version_major = 0x1;
+	dsc->dsc_version_minor = 0x2;
+
+	dsc->slice_height = 20;
+	dsc->slice_width = 540;
+	dsc->slice_count = 2;
+	dsc->bits_per_component = 8;
+	dsc->bits_per_pixel = 0x8 << 4;
+	dsc->block_pred_enable = true;
+
+	dsi->dsc = dsc;
+
+	ctx->supplies[0].supply = "vddio";
+	ctx->supplies[1].supply = "vdd";
+
+	ret = devm_regulator_bulk_get(&dsi->dev, ARRAY_SIZE(ctx->supplies),
+			ctx->supplies);
+
+	if (ret < 0)
+		return ret;
+
+	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");
+
+	ctx->dsi = dsi;
+	mipi_dsi_set_drvdata(dsi, ctx);
+
+	dsi->lanes = 4;
+	dsi->format = MIPI_DSI_FMT_RGB888;
+	dsi->mode_flags = MIPI_DSI_MODE_LPM | MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+	drm_panel_init(&ctx->panel, dev, &visionox_r66451_funcs, DRM_MODE_CONNECTOR_DSI);
+	ctx->panel.backlight = visionox_r66451_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;
+}
+
+static void visionox_r66451_remove(struct mipi_dsi_device *dsi)
+{
+	struct visionox_r66451 *ctx = mipi_dsi_get_drvdata(dsi);
+	int ret;
+
+	ret = mipi_dsi_detach(dsi);
+	if (ret < 0)
+		dev_err(&dsi->dev, "Failed to detach DSI host: %d\n", ret);
+
+	drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id visionox_r66451_of_match[] = {
+	{.compatible = "visionox,r66451"},
+	{ /*sentinel*/ }
+};
+MODULE_DEVICE_TABLE(of, visionox_r66451_of_match);
+
+static struct mipi_dsi_driver visionox_r66451_driver = {
+	.probe = visionox_r66451_probe,
+	.remove = visionox_r66451_remove,
+	.driver = {
+		.name = "panel-visionox-r66451",
+		.of_match_table = visionox_r66451_of_match,
+	},
+};
+
+module_mipi_dsi_driver(visionox_r66451_driver);
+
+MODULE_AUTHOR("Jessica Zhang <[email protected]>");
+MODULE_DESCRIPTION("Panel driver for the Visionox R66451 AMOLED DSI panel");
+MODULE_LICENSE("GPL");
Signature · 2 lines
With best wishes
Dmitry
#10 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

Quoted 156 lines · Dmitry Baryshkov
Quoted 155 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
  drivers/gpu/drm/panel/Kconfig                 |   8 + drivers/gpu/drm/panel/Makefile                |   1 + drivers/gpu/drm/panel/panel-visionox-r66451.c | 395
++++++++++++++++++++++++++

  3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +0 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130

        Say Y here if you want to enable support for Visionox VTDR6130 1080x2400 AMOLED DSI panel.

drivers/gpu/drm/panel/Kconfig +8 -0
+config DRM_PANEL_VISIONOX_R66451
+    tristate "Visionox R66451"
+    depends on OF
+    depends on DRM_MIPI_DSI
+    help
+      Say Y here if you want to enable support for Visionox
+      R66451 1080x2340 AMOLED DSI panel.
+

  config DRM_PANEL_WIDECHIPS_WS2401 tristate "Widechips WS2401 DPI panel driver" depends on SPI && GPIOLIB

drivers/gpu/drm/panel/Makefile +0 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += 

panel-tpo-tpg110.o
  obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o +obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +2 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights 

reserved.

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +25 -0
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+    struct drm_panel panel;
+    struct mipi_dsi_device *dsi;
+    struct gpio_desc *reset_gpio;
+    struct regulator_bulk_data supplies[2];
+    bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct 

drm_panel *panel)

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +34 -0
+{
+    return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc2,
+                   0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
+                   0x09, 0x3c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xde,
+                   0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+                   0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02, 

0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc4,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +                   0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32); +    mipi_dsi_dcs_write_seq(dsi, 0xcf,
+                   0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, +                   0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +                   0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+    mipi_dsi_dcs_write_seq(dsi, 0xd3,
+                   0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07, +                   0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0, +                   0x3c, 0x9c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a, +                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, +                   0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a); +    mipi_dsi_dcs_write_seq(dsi, 0xd8,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +                   0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, +                   0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +                   0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, +                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, +                   0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf,
+                   0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00, +                   0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +                   0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00, +                   0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00, +                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00, 0x39, 0x04, 0x09, 0x34);
+    mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00); +    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01);

Quoted 8 lines
Quoted 6 lines

+    mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+    mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK); +    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x04, 0x37);

Please use mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1);

Hi Dmitry,

Acked.

Quoted 5 lines
Quoted 3 lines

+    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00, 0x09, 0x23);

mipi_dsi_dcs_set_page_address(dsi, 0, 2340 - 1);

Acked.

Quoted 12 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 117

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -0
+
+    ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    ret = mipi_dsi_dcs_set_display_on(dsi);

Should the mipi_dsi_dcs_set_display_on() (and maybe exit sleep mode) be a a part of _enable()? Correspondingly _off should IMO be a part of _disable callback().

Acked. Looking at the downstream code, it seems that all the dcs on commands can be sent within _enable() (and similarly for the off commands with _disable()).

Quoted 11 lines
Quoted 6 lines

+    if (ret < 0) {
+        dev_err(dev, "Failed on set display on: %d\n", ret); +        return ret;
+    }
+    msleep(20);

Do we need to add here the following line?

dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

Do you mean within the return on error block?

From my understanding, we should be setting the MIPI_DSI_MODE_LPM for panel_on() then unsetting MODE_LPM in panel_off().

Quoted 86 lines
Quoted 86 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +50 -0
+
+    return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+    ret = mipi_dsi_dcs_set_display_off(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to set display off: %d\n", ret);
+        return ret;
+    }
+    msleep(20);
+
+    ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(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)
+        return ret;
+
+    visionox_r66451_reset(ctx);
+
+    ret = visionox_r66451_on(ctx);
+    if (ret < 0) {
+        dev_err(dev, "Failed to initialize panel: %d\n", ret);
+        gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+        regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), 

ctx->supplies);
+        return ret;
+    }

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +31 -0
+
+    ctx->prepared = true;
+    return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct device *dev = &ctx->dsi->dev;
+    int ret;
+
+    if (!ctx->prepared)
+        return 0;
+
+    ret = visionox_r66451_off(ctx);
+    if (ret < 0)
+        dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+    ctx->prepared = false;
+    return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+    .clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,
+    .hdisplay = 1080,
+    .hsync_start = 1080 + 95,
+    .hsync_end = 1080 + 95 + 1,
+    .htotal = 1080 + 95 + 1 + 40,
Quoted 8 lines
Quoted 6 lines

+    .vdisplay = 2340,
+    .vsync_start = 2340 + 25,
+    .vsync_end = 2340 + 25 + 1,
+    .vtotal = 2340 + 25 + 1 + 4,
+    .width_mm = 0,
+    .height_mm = 0,

Please provide real values here.

Acked.

Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +43 -0
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct drm_dsc_picture_parameter_set pps;
+    int ret;
+
+    if (ctx->enabled)
+        return 0;
+
+    if (!dsi->dsc) {
+        dev_err(&dsi->dev, "DSC not attached to DSI\n");
+        return -ENODEV;
+    }
+
+    drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+    ret = mipi_dsi_picture_parameter_set(dsi, &pps);
+
+    ctx->enabled = true;
+
+    return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+    ctx->enabled = false;
+
+    return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+                    struct drm_connector *connector)
+{
+    struct drm_display_mode *mode;
+
+    mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+    if (!mode)
+        return -ENOMEM;
+
Quoted 8 lines
Quoted 6 lines

+    drm_mode_set_name(mode);
+
+    mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; +    connector->display_info.width_mm = mode->width_mm; +    connector->display_info.height_mm = mode->height_mm; +    drm_mode_probed_add(connector, mode);

Can we use drm_connector_helper_get_modes_fixed() instead?

Acked.

Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +13 -0
+
+    return 1;
+}
+
+static const struct drm_panel_funcs visionox_r66451_funcs = {
+    .prepare = visionox_r66451_prepare,
+    .unprepare = visionox_r66451_unprepare,
+    .get_modes = visionox_r66451_get_modes,
+    .enable = visionox_r66451_enable,
+    .disable = visionox_r66451_disable,
+};
+
+static int visionox_r66451_bl_update_status(struct backlight_device *bl)
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+{
+    struct mipi_dsi_device *dsi = bl_get_data(bl);
+    u16 brightness = backlight_get_brightness(bl);
+
+    return mipi_dsi_dcs_set_display_brightness(dsi, 

cpu_to_le16(brightness));

mipi_dsi_dcs_set_display_brightness() already converts the brightness, so you don't need cpu_to_le16 here.

Acked.

Thanks,

Jessica Zhang

Quoted 127 lines
Quoted 122 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +60 -0
+}
+
+static const struct backlight_ops visionox_r66451_bl_ops = {
+    .update_status = visionox_r66451_bl_update_status,
+};
+
+static struct backlight_device *
+visionox_r66451_create_backlight(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    const struct backlight_properties props = {
+        .type = BACKLIGHT_RAW,
+        .brightness = 255,
+        .max_brightness = 4095,
+    };
+
+    return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+                          &visionox_r66451_bl_ops, &props);
+}
+
+static int visionox_r66451_probe(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    struct visionox_r66451 *ctx;
+    struct drm_dsc_config *dsc;
+    int ret = 0;
+
+    ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+    if (!ctx)
+        return -ENOMEM;
+
+    dsc = devm_kzalloc(dev, sizeof(*dsc), GFP_KERNEL);
+    if (!dsc)
+        return -ENOMEM;
+
+    /* Set DSC params */
+    dsc->dsc_version_major = 0x1;
+    dsc->dsc_version_minor = 0x2;
+
+    dsc->slice_height = 20;
+    dsc->slice_width = 540;
+    dsc->slice_count = 2;
+    dsc->bits_per_component = 8;
+    dsc->bits_per_pixel = 0x8 << 4;
+    dsc->block_pred_enable = true;
+
+    dsi->dsc = dsc;
+
+    ctx->supplies[0].supply = "vddio";
+    ctx->supplies[1].supply = "vdd";
+
+    ret = devm_regulator_bulk_get(&dsi->dev, ARRAY_SIZE(ctx->supplies),
+            ctx->supplies);
+
+    if (ret < 0)
+        return ret;
+
+    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");

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -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_LPM | MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+    drm_panel_init(&ctx->panel, dev, &visionox_r66451_funcs, 

DRM_MODE_CONNECTOR_DSI);
+    ctx->panel.backlight = visionox_r66451_create_backlight(dsi); +    if (IS_ERR(ctx->panel.backlight))
+        return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight), +                "Failed to create backlight\n");

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +43 -0
+
+    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;
+}
+
+static void visionox_r66451_remove(struct mipi_dsi_device *dsi)
+{
+    struct visionox_r66451 *ctx = mipi_dsi_get_drvdata(dsi);
+    int ret;
+
+    ret = mipi_dsi_detach(dsi);
+    if (ret < 0)
+        dev_err(&dsi->dev, "Failed to detach DSI host: %d\n", ret);
+
+    drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id visionox_r66451_of_match[] = {
+    {.compatible = "visionox,r66451"},
+    { /*sentinel*/ }
+};
+MODULE_DEVICE_TABLE(of, visionox_r66451_of_match);
+
+static struct mipi_dsi_driver visionox_r66451_driver = {
+    .probe = visionox_r66451_probe,
+    .remove = visionox_r66451_remove,
+    .driver = {
+        .name = "panel-visionox-r66451",
+        .of_match_table = visionox_r66451_of_match,
+    },
+};
+
+module_mipi_dsi_driver(visionox_r66451_driver);
+
+MODULE_AUTHOR("Jessica Zhang <[email protected]>");
+MODULE_DESCRIPTION("Panel driver for the Visionox R66451 AMOLED DSI 

panel");
+MODULE_LICENSE("GPL");

Signature · 2 lines
With best wishes
Dmitry
#11 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

Quoted 200 lines · Jessica Zhang
Quoted 160 lines · Dmitry Baryshkov
Quoted 159 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
  drivers/gpu/drm/panel/Kconfig                 |   8 +
  drivers/gpu/drm/panel/Makefile                |   1 +
  drivers/gpu/drm/panel/panel-visionox-r66451.c | 395
++++++++++++++++++++++++++
  3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +8 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130
        Say Y here if you want to enable support for Visionox
        VTDR6130 1080x2400 AMOLED DSI panel.
+config DRM_PANEL_VISIONOX_R66451
+    tristate "Visionox R66451"
+    depends on OF
+    depends on DRM_MIPI_DSI
+    help
+      Say Y here if you want to enable support for Visionox
+      R66451 1080x2340 AMOLED DSI panel.
+
  config DRM_PANEL_WIDECHIPS_WS2401
      tristate "Widechips WS2401 DPI panel driver"
      depends on SPI && GPIOLIB
drivers/gpu/drm/panel/Makefile +0 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) +=

panel-tpo-tpg110.o
obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o
+obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o
obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) +=
panel-xinpeng-xpp055c272.o

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +2 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights

reserved.

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +25 -0
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+    struct drm_panel panel;
+    struct mipi_dsi_device *dsi;
+    struct gpio_desc *reset_gpio;
+    struct regulator_bulk_data supplies[2];
+    bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct

drm_panel *panel)

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +34 -0
+{
+    return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc2,
+                   0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
+                   0x09, 0x3c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xde,
+                   0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+                   0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02,

0x00, 0x00);

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +35 -0
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc4,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32);
+    mipi_dsi_dcs_write_seq(dsi, 0xcf,
+                   0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
+                   0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+                   0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+    mipi_dsi_dcs_write_seq(dsi, 0xd3,
+                   0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07,
+                   0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0,
+                   0x3c, 0x9c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+    mipi_dsi_dcs_write_seq(dsi, 0xd8,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a,
+                   0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
+                   0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf,
+                   0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00,

0x39, 0x04, 0x09, 0x34);

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+    mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01);
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+    mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+    mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
+    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00,

0x00, 0x04, 0x37);

Please use mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1);

Hi Dmitry,

Acked.

Quoted 5 lines
Quoted 3 lines

+ mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00,
0x00, 0x09, 0x23);

mipi_dsi_dcs_set_page_address(dsi, 0, 2340 - 1);

Acked.

Quoted 14 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 117

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -0
+
+    ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    ret = mipi_dsi_dcs_set_display_on(dsi);

Should the mipi_dsi_dcs_set_display_on() (and maybe exit sleep mode) be a a part of _enable()? Correspondingly _off should IMO be a part of _disable callback().

Quoted 3 lines

Acked. Looking at the downstream code, it seems that all the dcs on commands can be sent within _enable() (and similarly for the off commands with _disable()).

I wouldn't check against the downstream. The distinction is that prepare() is called before enabling the video stream and as such it usually contains commands to set up the panel parameters. The enable() callback is called after starting the video stream, so it should just turn on the image output, the backlight, etc..

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+    if (ret < 0) {
+        dev_err(dev, "Failed on set display on: %d\n", ret);
+        return ret;
+    }
+    msleep(20);
Quoted 5 lines
Quoted 3 lines

Do we need to add here the following line?

dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

Do you mean within the return on error block?

Within the return. I think this might depend on the panel itself, see how other panels handle toggling MIPI_DSI_MODE_LPM. E.g. panel-dsi-cm or panel-novatek-nt35950 unsets MIPI_DSI_MODE_LPM at the end of power_on. Some of the panels also toggle LPM while reading or updating the backlight.

Quoted 313 lines

From my understanding, we should be setting the MIPI_DSI_MODE_LPM for
panel_on() then unsetting MODE_LPM in panel_off().

Quoted 86 lines
Quoted 86 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +50 -0
+
+    return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+    ret = mipi_dsi_dcs_set_display_off(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to set display off: %d\n", ret);
+        return ret;
+    }
+    msleep(20);
+
+    ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(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)
+        return ret;
+
+    visionox_r66451_reset(ctx);
+
+    ret = visionox_r66451_on(ctx);
+    if (ret < 0) {
+        dev_err(dev, "Failed to initialize panel: %d\n", ret);
+        gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+        regulator_bulk_disable(ARRAY_SIZE(ctx->supplies),

ctx->supplies);

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +33 -0
+        return ret;
+    }
+
+    ctx->prepared = true;
+    return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct device *dev = &ctx->dsi->dev;
+    int ret;
+
+    if (!ctx->prepared)
+        return 0;
+
+    ret = visionox_r66451_off(ctx);
+    if (ret < 0)
+        dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+    ctx->prepared = false;
+    return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+    .clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,
+    .hdisplay = 1080,
+    .hsync_start = 1080 + 95,
+    .hsync_end = 1080 + 95 + 1,
+    .htotal = 1080 + 95 + 1 + 40,
Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 211

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+    .vdisplay = 2340,
+    .vsync_start = 2340 + 25,
+    .vsync_end = 2340 + 25 + 1,
+    .vtotal = 2340 + 25 + 1 + 4,
+    .width_mm = 0,
+    .height_mm = 0,

Please provide real values here.

Acked.

Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +43 -0
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct drm_dsc_picture_parameter_set pps;
+    int ret;
+
+    if (ctx->enabled)
+        return 0;
+
+    if (!dsi->dsc) {
+        dev_err(&dsi->dev, "DSC not attached to DSI\n");
+        return -ENODEV;
+    }
+
+    drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+    ret = mipi_dsi_picture_parameter_set(dsi, &pps);
+
+    ctx->enabled = true;
+
+    return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+    ctx->enabled = false;
+
+    return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+                    struct drm_connector *connector)
+{
+    struct drm_display_mode *mode;
+
+    mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+    if (!mode)
+        return -ENOMEM;
+
Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 260

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+    drm_mode_set_name(mode);
+
+    mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+    connector->display_info.width_mm = mode->width_mm;
+    connector->display_info.height_mm = mode->height_mm;
+    drm_mode_probed_add(connector, mode);

Can we use drm_connector_helper_get_modes_fixed() instead?

Acked.

Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +14 -0
+
+    return 1;
+}
+
+static const struct drm_panel_funcs visionox_r66451_funcs = {
+    .prepare = visionox_r66451_prepare,
+    .unprepare = visionox_r66451_unprepare,
+    .get_modes = visionox_r66451_get_modes,
+    .enable = visionox_r66451_enable,
+    .disable = visionox_r66451_disable,
+};
+
+static int visionox_r66451_bl_update_status(struct backlight_device *bl)
+{
Quoted 8 lines
Quoted 5 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +4 -0
+    struct mipi_dsi_device *dsi = bl_get_data(bl);
+    u16 brightness = backlight_get_brightness(bl);
+
+    return mipi_dsi_dcs_set_display_brightness(dsi,

cpu_to_le16(brightness));

mipi_dsi_dcs_set_display_brightness() already converts the brightness, so you don't need cpu_to_le16 here.

Acked.

Thanks,

Jessica Zhang

Quoted 127 lines
Quoted 119 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +60 -0
+}
+
+static const struct backlight_ops visionox_r66451_bl_ops = {
+    .update_status = visionox_r66451_bl_update_status,
+};
+
+static struct backlight_device *
+visionox_r66451_create_backlight(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    const struct backlight_properties props = {
+        .type = BACKLIGHT_RAW,
+        .brightness = 255,
+        .max_brightness = 4095,
+    };
+
+    return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+                          &visionox_r66451_bl_ops, &props);
+}
+
+static int visionox_r66451_probe(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    struct visionox_r66451 *ctx;
+    struct drm_dsc_config *dsc;
+    int ret = 0;
+
+    ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+    if (!ctx)
+        return -ENOMEM;
+
+    dsc = devm_kzalloc(dev, sizeof(*dsc), GFP_KERNEL);
+    if (!dsc)
+        return -ENOMEM;
+
+    /* Set DSC params */
+    dsc->dsc_version_major = 0x1;
+    dsc->dsc_version_minor = 0x2;
+
+    dsc->slice_height = 20;
+    dsc->slice_width = 540;
+    dsc->slice_count = 2;
+    dsc->bits_per_component = 8;
+    dsc->bits_per_pixel = 0x8 << 4;
+    dsc->block_pred_enable = true;
+
+    dsi->dsc = dsc;
+
+    ctx->supplies[0].supply = "vddio";
+    ctx->supplies[1].supply = "vdd";
+
+    ret = devm_regulator_bulk_get(&dsi->dev, ARRAY_SIZE(ctx->supplies),
+            ctx->supplies);
+
+    if (ret < 0)
+        return ret;
+
+    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");

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -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_LPM | MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+    drm_panel_init(&ctx->panel, dev, &visionox_r66451_funcs,

DRM_MODE_CONNECTOR_DSI);

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +47 -0
+    ctx->panel.backlight = visionox_r66451_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;
+}
+
+static void visionox_r66451_remove(struct mipi_dsi_device *dsi)
+{
+    struct visionox_r66451 *ctx = mipi_dsi_get_drvdata(dsi);
+    int ret;
+
+    ret = mipi_dsi_detach(dsi);
+    if (ret < 0)
+        dev_err(&dsi->dev, "Failed to detach DSI host: %d\n", ret);
+
+    drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id visionox_r66451_of_match[] = {
+    {.compatible = "visionox,r66451"},
+    { /*sentinel*/ }
+};
+MODULE_DEVICE_TABLE(of, visionox_r66451_of_match);
+
+static struct mipi_dsi_driver visionox_r66451_driver = {
+    .probe = visionox_r66451_probe,
+    .remove = visionox_r66451_remove,
+    .driver = {
+        .name = "panel-visionox-r66451",
+        .of_match_table = visionox_r66451_of_match,
+    },
+};
+
+module_mipi_dsi_driver(visionox_r66451_driver);
+
+MODULE_AUTHOR("Jessica Zhang <[email protected]>");
+MODULE_DESCRIPTION("Panel driver for the Visionox R66451 AMOLED DSI
Quoted 3 lines

panel");
+MODULE_LICENSE("GPL");

--
With best wishes
Dmitry

Signature · 2 lines
With best wishes
Dmitry
#12 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

Quoted 205 lines · Dmitry Baryshkov
Quoted 200 lines · Jessica Zhang
Quoted 160 lines · Dmitry Baryshkov
Quoted 159 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
   drivers/gpu/drm/panel/Kconfig                 |   8 +
   drivers/gpu/drm/panel/Makefile                |   1 +
   drivers/gpu/drm/panel/panel-visionox-r66451.c | 395
++++++++++++++++++++++++++
   3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +8 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130
         Say Y here if you want to enable support for Visionox
         VTDR6130 1080x2400 AMOLED DSI panel.
+config DRM_PANEL_VISIONOX_R66451
+    tristate "Visionox R66451"
+    depends on OF
+    depends on DRM_MIPI_DSI
+    help
+      Say Y here if you want to enable support for Visionox
+      R66451 1080x2340 AMOLED DSI panel.
+
   config DRM_PANEL_WIDECHIPS_WS2401
       tristate "Widechips WS2401 DPI panel driver"
       depends on SPI && GPIOLIB
drivers/gpu/drm/panel/Makefile +0 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) +=

panel-tpo-tpg110.o
obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o
+obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o
obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) +=
panel-xinpeng-xpp055c272.o

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +2 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights

reserved.

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +25 -0
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+    struct drm_panel panel;
+    struct mipi_dsi_device *dsi;
+    struct gpio_desc *reset_gpio;
+    struct regulator_bulk_data supplies[2];
+    bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct

drm_panel *panel)

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +34 -0
+{
+    return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc2,
+                   0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
+                   0x09, 0x3c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xde,
+                   0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+                   0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02,

0x00, 0x00);

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +35 -0
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc4,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32);
+    mipi_dsi_dcs_write_seq(dsi, 0xcf,
+                   0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
+                   0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+                   0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+    mipi_dsi_dcs_write_seq(dsi, 0xd3,
+                   0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07,
+                   0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0,
+                   0x3c, 0x9c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+    mipi_dsi_dcs_write_seq(dsi, 0xd8,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a,
+                   0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
+                   0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf,
+                   0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00,

0x39, 0x04, 0x09, 0x34);

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+    mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01);
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+    mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+    mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
+    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00,

0x00, 0x04, 0x37);

Please use mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1);

Hi Dmitry,

Acked.

Quoted 5 lines
Quoted 3 lines

+ mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00,
0x00, 0x09, 0x23);

mipi_dsi_dcs_set_page_address(dsi, 0, 2340 - 1);

Acked.

Quoted 14 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 117

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -0
+
+    ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    ret = mipi_dsi_dcs_set_display_on(dsi);

Should the mipi_dsi_dcs_set_display_on() (and maybe exit sleep mode) be a a part of _enable()? Correspondingly _off should IMO be a part of _disable callback().

Quoted 3 lines

Acked. Looking at the downstream code, it seems that all the dcs on commands can be sent within _enable() (and similarly for the off commands with _disable()).

Quoted 5 lines

I wouldn't check against the downstream. The distinction is that prepare() is called before enabling the video stream and as such it usually contains commands to set up the panel parameters. The enable() callback is called after starting the video stream, so it should just turn on the image output, the backlight, etc..

Hi Dmitry,

Got it.

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 122

Quoted 8 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+    if (ret < 0) {
+        dev_err(dev, "Failed on set display on: %d\n", ret);
+        return ret;
+    }
+    msleep(20);

Do we need to add here the following line?

dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

Quoted 7 lines
Quoted 1 line

Do you mean within the return on error block?

Within the return. I think this might depend on the panel itself, see how other panels handle toggling MIPI_DSI_MODE_LPM. E.g. panel-dsi-cm or panel-novatek-nt35950 unsets MIPI_DSI_MODE_LPM at the end of power_on. Some of the panels also toggle LPM while reading or updating the backlight.

Understood. FWIW, I'm seeing that there are others like panel-visionox-vtdr6130.c that don't unset MODE_LPM after sending the DCS commands.

I'll double check what we should be doing for r66451.

Thanks,

Jessica Zhang

Quoted 320 lines
Quoted 314 lines

From my understanding, we should be setting the MIPI_DSI_MODE_LPM for
panel_on() then unsetting MODE_LPM in panel_off().

Quoted 86 lines
Quoted 86 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +50 -0
+
+    return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+    ret = mipi_dsi_dcs_set_display_off(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to set display off: %d\n", ret);
+        return ret;
+    }
+    msleep(20);
+
+    ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(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)
+        return ret;
+
+    visionox_r66451_reset(ctx);
+
+    ret = visionox_r66451_on(ctx);
+    if (ret < 0) {
+        dev_err(dev, "Failed to initialize panel: %d\n", ret);
+        gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+        regulator_bulk_disable(ARRAY_SIZE(ctx->supplies),

ctx->supplies);

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +33 -0
+        return ret;
+    }
+
+    ctx->prepared = true;
+    return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct device *dev = &ctx->dsi->dev;
+    int ret;
+
+    if (!ctx->prepared)
+        return 0;
+
+    ret = visionox_r66451_off(ctx);
+    if (ret < 0)
+        dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+    ctx->prepared = false;
+    return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+    .clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,
+    .hdisplay = 1080,
+    .hsync_start = 1080 + 95,
+    .hsync_end = 1080 + 95 + 1,
+    .htotal = 1080 + 95 + 1 + 40,
Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 211

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+    .vdisplay = 2340,
+    .vsync_start = 2340 + 25,
+    .vsync_end = 2340 + 25 + 1,
+    .vtotal = 2340 + 25 + 1 + 4,
+    .width_mm = 0,
+    .height_mm = 0,

Please provide real values here.

Acked.

Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +43 -0
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct drm_dsc_picture_parameter_set pps;
+    int ret;
+
+    if (ctx->enabled)
+        return 0;
+
+    if (!dsi->dsc) {
+        dev_err(&dsi->dev, "DSC not attached to DSI\n");
+        return -ENODEV;
+    }
+
+    drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+    ret = mipi_dsi_picture_parameter_set(dsi, &pps);
+
+    ctx->enabled = true;
+
+    return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+    ctx->enabled = false;
+
+    return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+                    struct drm_connector *connector)
+{
+    struct drm_display_mode *mode;
+
+    mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+    if (!mode)
+        return -ENOMEM;
+
Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 260

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+    drm_mode_set_name(mode);
+
+    mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+    connector->display_info.width_mm = mode->width_mm;
+    connector->display_info.height_mm = mode->height_mm;
+    drm_mode_probed_add(connector, mode);

Can we use drm_connector_helper_get_modes_fixed() instead?

Acked.

Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +14 -0
+
+    return 1;
+}
+
+static const struct drm_panel_funcs visionox_r66451_funcs = {
+    .prepare = visionox_r66451_prepare,
+    .unprepare = visionox_r66451_unprepare,
+    .get_modes = visionox_r66451_get_modes,
+    .enable = visionox_r66451_enable,
+    .disable = visionox_r66451_disable,
+};
+
+static int visionox_r66451_bl_update_status(struct backlight_device *bl)
+{
Quoted 8 lines
Quoted 5 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +4 -0
+    struct mipi_dsi_device *dsi = bl_get_data(bl);
+    u16 brightness = backlight_get_brightness(bl);
+
+    return mipi_dsi_dcs_set_display_brightness(dsi,

cpu_to_le16(brightness));

mipi_dsi_dcs_set_display_brightness() already converts the brightness, so you don't need cpu_to_le16 here.

Acked.

Thanks,

Jessica Zhang

Quoted 127 lines
Quoted 119 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +60 -0
+}
+
+static const struct backlight_ops visionox_r66451_bl_ops = {
+    .update_status = visionox_r66451_bl_update_status,
+};
+
+static struct backlight_device *
+visionox_r66451_create_backlight(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    const struct backlight_properties props = {
+        .type = BACKLIGHT_RAW,
+        .brightness = 255,
+        .max_brightness = 4095,
+    };
+
+    return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+                          &visionox_r66451_bl_ops, &props);
+}
+
+static int visionox_r66451_probe(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    struct visionox_r66451 *ctx;
+    struct drm_dsc_config *dsc;
+    int ret = 0;
+
+    ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+    if (!ctx)
+        return -ENOMEM;
+
+    dsc = devm_kzalloc(dev, sizeof(*dsc), GFP_KERNEL);
+    if (!dsc)
+        return -ENOMEM;
+
+    /* Set DSC params */
+    dsc->dsc_version_major = 0x1;
+    dsc->dsc_version_minor = 0x2;
+
+    dsc->slice_height = 20;
+    dsc->slice_width = 540;
+    dsc->slice_count = 2;
+    dsc->bits_per_component = 8;
+    dsc->bits_per_pixel = 0x8 << 4;
+    dsc->block_pred_enable = true;
+
+    dsi->dsc = dsc;
+
+    ctx->supplies[0].supply = "vddio";
+    ctx->supplies[1].supply = "vdd";
+
+    ret = devm_regulator_bulk_get(&dsi->dev, ARRAY_SIZE(ctx->supplies),
+            ctx->supplies);
+
+    if (ret < 0)
+        return ret;
+
+    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");

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -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_LPM | MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+    drm_panel_init(&ctx->panel, dev, &visionox_r66451_funcs,

DRM_MODE_CONNECTOR_DSI);

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +47 -0
+    ctx->panel.backlight = visionox_r66451_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;
+}
+
+static void visionox_r66451_remove(struct mipi_dsi_device *dsi)
+{
+    struct visionox_r66451 *ctx = mipi_dsi_get_drvdata(dsi);
+    int ret;
+
+    ret = mipi_dsi_detach(dsi);
+    if (ret < 0)
+        dev_err(&dsi->dev, "Failed to detach DSI host: %d\n", ret);
+
+    drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id visionox_r66451_of_match[] = {
+    {.compatible = "visionox,r66451"},
+    { /*sentinel*/ }
+};
+MODULE_DEVICE_TABLE(of, visionox_r66451_of_match);
+
+static struct mipi_dsi_driver visionox_r66451_driver = {
+    .probe = visionox_r66451_probe,
+    .remove = visionox_r66451_remove,
+    .driver = {
+        .name = "panel-visionox-r66451",
+        .of_match_table = visionox_r66451_of_match,
+    },
+};
+
+module_mipi_dsi_driver(visionox_r66451_driver);
+
+MODULE_AUTHOR("Jessica Zhang <[email protected]>");
+MODULE_DESCRIPTION("Panel driver for the Visionox R66451 AMOLED DSI
Quoted 3 lines

panel");
+MODULE_LICENSE("GPL");

--
With best wishes
Dmitry

Signature · 2 lines
With best wishes
Dmitry
#13 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

In reply to Jessica Zhang
Quoted 382 lines · Jessica Zhang
Quoted 176 lines · Dmitry Baryshkov
Quoted 175 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
  drivers/gpu/drm/panel/Kconfig                 |   8 + drivers/gpu/drm/panel/Makefile                |   1 + drivers/gpu/drm/panel/panel-visionox-r66451.c | 395
++++++++++++++++++++++++++

  3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +0 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130

        Say Y here if you want to enable support for Visionox VTDR6130 1080x2400 AMOLED DSI panel.

drivers/gpu/drm/panel/Kconfig +8 -0
+config DRM_PANEL_VISIONOX_R66451
+    tristate "Visionox R66451"
+    depends on OF
+    depends on DRM_MIPI_DSI
+    help
+      Say Y here if you want to enable support for Visionox
+      R66451 1080x2340 AMOLED DSI panel.
+

  config DRM_PANEL_WIDECHIPS_WS2401 tristate "Widechips WS2401 DPI panel driver" depends on SPI && GPIOLIB

drivers/gpu/drm/panel/Makefile +0 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += 

panel-tpo-tpg110.o
  obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o +obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +2 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights 

reserved.

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +25 -0
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+    struct drm_panel panel;
+    struct mipi_dsi_device *dsi;
+    struct gpio_desc *reset_gpio;
+    struct regulator_bulk_data supplies[2];
+    bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct 

drm_panel *panel)

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +25 -0
+{
+    return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc2,
+                   0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 

0x00,
+                   0x09, 0x3c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a); +    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xde,
+                   0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+                   0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc4,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32); +    mipi_dsi_dcs_write_seq(dsi, 0xcf,
+                   0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
+                   0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+                   0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+    mipi_dsi_dcs_write_seq(dsi, 0xd3,
+                   0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07,
+                   0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0,
+                   0x3c, 0x9c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a); +    mipi_dsi_dcs_write_seq(dsi, 0xd8,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a,
+                   0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
+                   0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf,
+                   0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00, 0x39, 0x04, 0x09, 0x34);
+    mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00); +    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01);

Quoted 8 lines
Quoted 6 lines

+    mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+    mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK); +    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x04, 0x37);

Please use mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1);

Hi Dmitry,

Acked.

Quoted 5 lines
Quoted 3 lines

+    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00, 0x09, 0x23);

mipi_dsi_dcs_set_page_address(dsi, 0, 2340 - 1);

Acked.

Quoted 12 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 117

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -0
+
+    ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    ret = mipi_dsi_dcs_set_display_on(dsi);

Should the mipi_dsi_dcs_set_display_on() (and maybe exit sleep mode) be a a part of _enable()? Correspondingly _off should IMO be a part of _disable callback().

Acked. Looking at the downstream code, it seems that all the dcs on commands can be sent within _enable() (and similarly for the off commands with _disable()).

Quoted 11 lines
Quoted 6 lines

+    if (ret < 0) {
+        dev_err(dev, "Failed on set display on: %d\n", ret); +        return ret;
+    }
+    msleep(20);

Do we need to add here the following line?

dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

Do you mean within the return on error block?

From my understanding, we should be setting the MIPI_DSI_MODE_LPM for
panel_on() then unsetting MODE_LPM in panel_off().

Quoted 86 lines
Quoted 86 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +50 -0
+
+    return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+    ret = mipi_dsi_dcs_set_display_off(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to set display off: %d\n", ret);
+        return ret;
+    }
+    msleep(20);
+
+    ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(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)
+        return ret;
+
+    visionox_r66451_reset(ctx);
+
+    ret = visionox_r66451_on(ctx);
+    if (ret < 0) {
+        dev_err(dev, "Failed to initialize panel: %d\n", ret);
+        gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+        regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), 

ctx->supplies);
+        return ret;
+    }

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +31 -0
+
+    ctx->prepared = true;
+    return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct device *dev = &ctx->dsi->dev;
+    int ret;
+
+    if (!ctx->prepared)
+        return 0;
+
+    ret = visionox_r66451_off(ctx);
+    if (ret < 0)
+        dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+    ctx->prepared = false;
+    return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+    .clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,
+    .hdisplay = 1080,
+    .hsync_start = 1080 + 95,
+    .hsync_end = 1080 + 95 + 1,
+    .htotal = 1080 + 95 + 1 + 40,
Quoted 8 lines
Quoted 6 lines

+    .vdisplay = 2340,
+    .vsync_start = 2340 + 25,
+    .vsync_end = 2340 + 25 + 1,
+    .vtotal = 2340 + 25 + 1 + 4,
+    .width_mm = 0,
+    .height_mm = 0,

Please provide real values here.

Acked.

Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +43 -0
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct drm_dsc_picture_parameter_set pps;
+    int ret;
+
+    if (ctx->enabled)
+        return 0;
+
+    if (!dsi->dsc) {
+        dev_err(&dsi->dev, "DSC not attached to DSI\n");
+        return -ENODEV;
+    }
+
+    drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+    ret = mipi_dsi_picture_parameter_set(dsi, &pps);
+
+    ctx->enabled = true;
+
+    return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+    ctx->enabled = false;
+
+    return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+                    struct drm_connector *connector)
+{
+    struct drm_display_mode *mode;
+
+    mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+    if (!mode)
+        return -ENOMEM;
+
Quoted 8 lines
Quoted 6 lines

+    drm_mode_set_name(mode);
+
+    mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; +    connector->display_info.width_mm = mode->width_mm; +    connector->display_info.height_mm = mode->height_mm; +    drm_mode_probed_add(connector, mode);

Can we use drm_connector_helper_get_modes_fixed() instead?

Quoted 1 line

Acked.

Hi Dmitry,

Just wanted to follow up on this -- As Marijn mentioned in a separated thread, DRM_MODE_TYPE_DRIVER is not set within drm_connector_helper_get_modes_fixed(), and looking at the kernel docs, that's a required flag for this mode.

Since I'm not able to set the *_TYPE_DRIVER flag before *_get_modes_fixed() is called, I'll stick to using the previous method of calling drm_mode_probed_add() directly in visionox_r66451_get_modes(). (FWIW, other drivers such as panel-visionox-vtdr6130, panel-truly-nt35597, and panel-visionox-rm69299 also don't use *_get_modes_fixed() and call drm_mode_probed_add() directly in their get_mode() implementations.)

Thanks,

Jessica Zhang

Quoted 159 lines
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +13 -0
+
+    return 1;
+}
+
+static const struct drm_panel_funcs visionox_r66451_funcs = {
+    .prepare = visionox_r66451_prepare,
+    .unprepare = visionox_r66451_unprepare,
+    .get_modes = visionox_r66451_get_modes,
+    .enable = visionox_r66451_enable,
+    .disable = visionox_r66451_disable,
+};
+
+static int visionox_r66451_bl_update_status(struct backlight_device 

*bl)

Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+{
+    struct mipi_dsi_device *dsi = bl_get_data(bl);
+    u16 brightness = backlight_get_brightness(bl);
+
+    return mipi_dsi_dcs_set_display_brightness(dsi, 

cpu_to_le16(brightness));

mipi_dsi_dcs_set_display_brightness() already converts the brightness, so you don't need cpu_to_le16 here.

Acked.

Thanks,

Jessica Zhang

Quoted 128 lines
Quoted 123 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +60 -0
+}
+
+static const struct backlight_ops visionox_r66451_bl_ops = {
+    .update_status = visionox_r66451_bl_update_status,
+};
+
+static struct backlight_device *
+visionox_r66451_create_backlight(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    const struct backlight_properties props = {
+        .type = BACKLIGHT_RAW,
+        .brightness = 255,
+        .max_brightness = 4095,
+    };
+
+    return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+                          &visionox_r66451_bl_ops, &props);
+}
+
+static int visionox_r66451_probe(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    struct visionox_r66451 *ctx;
+    struct drm_dsc_config *dsc;
+    int ret = 0;
+
+    ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+    if (!ctx)
+        return -ENOMEM;
+
+    dsc = devm_kzalloc(dev, sizeof(*dsc), GFP_KERNEL);
+    if (!dsc)
+        return -ENOMEM;
+
+    /* Set DSC params */
+    dsc->dsc_version_major = 0x1;
+    dsc->dsc_version_minor = 0x2;
+
+    dsc->slice_height = 20;
+    dsc->slice_width = 540;
+    dsc->slice_count = 2;
+    dsc->bits_per_component = 8;
+    dsc->bits_per_pixel = 0x8 << 4;
+    dsc->block_pred_enable = true;
+
+    dsi->dsc = dsc;
+
+    ctx->supplies[0].supply = "vddio";
+    ctx->supplies[1].supply = "vdd";
+
+    ret = devm_regulator_bulk_get(&dsi->dev, ARRAY_SIZE(ctx->supplies),
+            ctx->supplies);
+
+    if (ret < 0)
+        return ret;
+
+    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");

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +7 -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_LPM | 

MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+    drm_panel_init(&ctx->panel, dev, &visionox_r66451_funcs, DRM_MODE_CONNECTOR_DSI);
+    ctx->panel.backlight = visionox_r66451_create_backlight(dsi); +    if (IS_ERR(ctx->panel.backlight))
+        return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight), +                "Failed to create backlight\n");

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +43 -0
+
+    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;
+}
+
+static void visionox_r66451_remove(struct mipi_dsi_device *dsi)
+{
+    struct visionox_r66451 *ctx = mipi_dsi_get_drvdata(dsi);
+    int ret;
+
+    ret = mipi_dsi_detach(dsi);
+    if (ret < 0)
+        dev_err(&dsi->dev, "Failed to detach DSI host: %d\n", ret);
+
+    drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id visionox_r66451_of_match[] = {
+    {.compatible = "visionox,r66451"},
+    { /*sentinel*/ }
+};
+MODULE_DEVICE_TABLE(of, visionox_r66451_of_match);
+
+static struct mipi_dsi_driver visionox_r66451_driver = {
+    .probe = visionox_r66451_probe,
+    .remove = visionox_r66451_remove,
+    .driver = {
+        .name = "panel-visionox-r66451",
+        .of_match_table = visionox_r66451_of_match,
+    },
+};
+
+module_mipi_dsi_driver(visionox_r66451_driver);
+
+MODULE_AUTHOR("Jessica Zhang <[email protected]>");
+MODULE_DESCRIPTION("Panel driver for the Visionox R66451 AMOLED DSI 

panel");
+MODULE_LICENSE("GPL");

Signature · 2 lines
With best wishes
Dmitry
#14 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

Quoted 384 lines · Jessica Zhang
Quoted 381 lines · Jessica Zhang
Quoted 176 lines · Dmitry Baryshkov
Quoted 175 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
  drivers/gpu/drm/panel/Kconfig                 |   8 + drivers/gpu/drm/panel/Makefile                |   1 + drivers/gpu/drm/panel/panel-visionox-r66451.c | 395
++++++++++++++++++++++++++

  3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +0 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130

        Say Y here if you want to enable support for Visionox VTDR6130 1080x2400 AMOLED DSI panel.

drivers/gpu/drm/panel/Kconfig +8 -0
+config DRM_PANEL_VISIONOX_R66451
+    tristate "Visionox R66451"
+    depends on OF
+    depends on DRM_MIPI_DSI
+    help
+      Say Y here if you want to enable support for Visionox
+      R66451 1080x2340 AMOLED DSI panel.
+

  config DRM_PANEL_WIDECHIPS_WS2401 tristate "Widechips WS2401 DPI panel driver" depends on SPI && GPIOLIB

drivers/gpu/drm/panel/Makefile +0 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += 

panel-tpo-tpg110.o
  obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o +obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +2 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights 

reserved.

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +25 -0
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+    struct drm_panel panel;
+    struct mipi_dsi_device *dsi;
+    struct gpio_desc *reset_gpio;
+    struct regulator_bulk_data supplies[2];
+    bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct 

drm_panel *panel)

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +25 -0
+{
+    return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc2,
+                   0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 

0x00,
+                   0x09, 0x3c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a); +    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xde,
+                   0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+                   0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc4,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32); +    mipi_dsi_dcs_write_seq(dsi, 0xcf,
+                   0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
+                   0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+                   0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+    mipi_dsi_dcs_write_seq(dsi, 0xd3,
+                   0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07,
+                   0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0,
+                   0x3c, 0x9c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a); +    mipi_dsi_dcs_write_seq(dsi, 0xd8,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a,
+                   0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
+                   0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf,
+                   0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00, 0x39, 0x04, 0x09, 0x34);
+    mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00); +    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01);

Quoted 8 lines
Quoted 6 lines

+    mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+    mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK); +    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x04, 0x37);

Please use mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1);

Hi Dmitry,

Acked.

Quoted 5 lines
Quoted 3 lines

+    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00, 0x09, 0x23);

mipi_dsi_dcs_set_page_address(dsi, 0, 2340 - 1);

Acked.

Quoted 12 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 117

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -0
+
+    ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    ret = mipi_dsi_dcs_set_display_on(dsi);

Should the mipi_dsi_dcs_set_display_on() (and maybe exit sleep mode) be a a part of _enable()? Correspondingly _off should IMO be a part of _disable callback().

Acked. Looking at the downstream code, it seems that all the dcs on commands can be sent within _enable() (and similarly for the off commands with _disable()).

Quoted 11 lines
Quoted 6 lines

+    if (ret < 0) {
+        dev_err(dev, "Failed on set display on: %d\n", ret); +        return ret;
+    }
+    msleep(20);

Do we need to add here the following line?

dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

Do you mean within the return on error block?

 From my understanding, we should be setting the MIPI_DSI_MODE_LPM for panel_on() then unsetting MODE_LPM in panel_off().

Quoted 86 lines
Quoted 86 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +50 -0
+
+    return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+    ret = mipi_dsi_dcs_set_display_off(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to set display off: %d\n", ret);
+        return ret;
+    }
+    msleep(20);
+
+    ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(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)
+        return ret;
+
+    visionox_r66451_reset(ctx);
+
+    ret = visionox_r66451_on(ctx);
+    if (ret < 0) {
+        dev_err(dev, "Failed to initialize panel: %d\n", ret);
+        gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+        regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), 

ctx->supplies);
+        return ret;
+    }

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +31 -0
+
+    ctx->prepared = true;
+    return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct device *dev = &ctx->dsi->dev;
+    int ret;
+
+    if (!ctx->prepared)
+        return 0;
+
+    ret = visionox_r66451_off(ctx);
+    if (ret < 0)
+        dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+    ctx->prepared = false;
+    return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+    .clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,
+    .hdisplay = 1080,
+    .hsync_start = 1080 + 95,
+    .hsync_end = 1080 + 95 + 1,
+    .htotal = 1080 + 95 + 1 + 40,
Quoted 8 lines
Quoted 6 lines

+    .vdisplay = 2340,
+    .vsync_start = 2340 + 25,
+    .vsync_end = 2340 + 25 + 1,
+    .vtotal = 2340 + 25 + 1 + 4,
+    .width_mm = 0,
+    .height_mm = 0,

Please provide real values here.

Acked.

Quoted 52 lines
Quoted 40 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +39 -0
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct drm_dsc_picture_parameter_set pps;
+    int ret;
+
+    if (ctx->enabled)
+        return 0;
+
+    if (!dsi->dsc) {
+        dev_err(&dsi->dev, "DSC not attached to DSI\n");
+        return -ENODEV;
+    }
+
+    drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+    ret = mipi_dsi_picture_parameter_set(dsi, &pps);
+
+    ctx->enabled = true;
+
+    return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+    ctx->enabled = false;
+
+    return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+                    struct drm_connector *connector)
+{
+    struct drm_display_mode *mode;
+

drivers/gpu/drm/panel/panel-visionox-r66451.c line 260

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+    mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+    if (!mode)
+        return -ENOMEM;
+
+    drm_mode_set_name(mode);
+
+    mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+    connector->display_info.width_mm = mode->width_mm;
+    connector->display_info.height_mm = mode->height_mm;
+    drm_mode_probed_add(connector, mode);

Can we use drm_connector_helper_get_modes_fixed() instead?

Quoted 5 lines
Quoted 1 line

Acked.

Hi Dmitry,

Just wanted to follow up on this -- As Marijn mentioned in a separated thread, DRM_MODE_TYPE_DRIVER is not set within drm_connector_helper_get_modes_fixed(), and looking at the kernel docs, that's a required flag for this mode.

You can set this flag in the visionox_r66451_mode, can you not?

Quoted 1 line

Since I'm not able to set the *_TYPE_DRIVER flag before *_get_modes_fixed() is called, I'll stick to using the previous method of calling drm_mode_probed_add() directly in visionox_r66451_get_modes(). (FWIW, other drivers such as panel-visionox-vtdr6130, panel-truly-nt35597, and panel-visionox-rm69299 also don't use *_get_modes_fixed() and call drm_mode_probed_add() directly in their get_mode() implementations.)

That doesn't mean that we should increase the amount of the c&p code.

If I have time, I'try doing a rework of existing panel drivers.

Signature · 2 lines
With best wishes
Dmitry
#15 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

Quoted 385 lines · Dmitry Baryshkov
Quoted 384 lines · Jessica Zhang
Quoted 381 lines · Jessica Zhang
Quoted 176 lines · Dmitry Baryshkov
Quoted 175 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
  drivers/gpu/drm/panel/Kconfig                 |   8 + drivers/gpu/drm/panel/Makefile                |   1 + drivers/gpu/drm/panel/panel-visionox-r66451.c | 395
++++++++++++++++++++++++++

  3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +0 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130

        Say Y here if you want to enable support for Visionox VTDR6130 1080x2400 AMOLED DSI panel.

drivers/gpu/drm/panel/Kconfig +8 -0
+config DRM_PANEL_VISIONOX_R66451
+    tristate "Visionox R66451"
+    depends on OF
+    depends on DRM_MIPI_DSI
+    help
+      Say Y here if you want to enable support for Visionox
+      R66451 1080x2340 AMOLED DSI panel.
+

  config DRM_PANEL_WIDECHIPS_WS2401 tristate "Widechips WS2401 DPI panel driver" depends on SPI && GPIOLIB

drivers/gpu/drm/panel/Makefile +0 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += 

panel-tpo-tpg110.o
  obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o +obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +2 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights 

reserved.

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +25 -0
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+    struct drm_panel panel;
+    struct mipi_dsi_device *dsi;
+    struct gpio_desc *reset_gpio;
+    struct regulator_bulk_data supplies[2];
+    bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct 

drm_panel *panel)

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +25 -0
+{
+    return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc2,
+                   0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 

0x00,
+                   0x09, 0x3c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a); +    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xde,
+                   0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+                   0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc4,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32); +    mipi_dsi_dcs_write_seq(dsi, 0xcf,
+                   0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
+                   0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+                   0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+    mipi_dsi_dcs_write_seq(dsi, 0xd3,
+                   0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07,
+                   0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0,
+                   0x3c, 0x9c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a); +    mipi_dsi_dcs_write_seq(dsi, 0xd8,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a,
+                   0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
+                   0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf,
+                   0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00, 0x39, 0x04, 0x09, 0x34);
+    mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00); +    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01);

Quoted 8 lines
Quoted 6 lines

+    mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+    mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK); +    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x04, 0x37);

Please use mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1);

Hi Dmitry,

Acked.

Quoted 5 lines
Quoted 3 lines

+    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00, 0x09, 0x23);

mipi_dsi_dcs_set_page_address(dsi, 0, 2340 - 1);

Acked.

Quoted 12 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 117

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -0
+
+    ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    ret = mipi_dsi_dcs_set_display_on(dsi);

Should the mipi_dsi_dcs_set_display_on() (and maybe exit sleep mode) be a a part of _enable()? Correspondingly _off should IMO be a part of _disable callback().

Acked. Looking at the downstream code, it seems that all the dcs on commands can be sent within _enable() (and similarly for the off commands with _disable()).

Quoted 11 lines
Quoted 6 lines

+    if (ret < 0) {
+        dev_err(dev, "Failed on set display on: %d\n", ret); +        return ret;
+    }
+    msleep(20);

Do we need to add here the following line?

dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

Do you mean within the return on error block?

 From my understanding, we should be setting the MIPI_DSI_MODE_LPM for panel_on() then unsetting MODE_LPM in panel_off().

Quoted 86 lines
Quoted 86 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +50 -0
+
+    return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+    ret = mipi_dsi_dcs_set_display_off(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to set display off: %d\n", ret);
+        return ret;
+    }
+    msleep(20);
+
+    ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(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)
+        return ret;
+
+    visionox_r66451_reset(ctx);
+
+    ret = visionox_r66451_on(ctx);
+    if (ret < 0) {
+        dev_err(dev, "Failed to initialize panel: %d\n", ret);
+        gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+        regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), 

ctx->supplies);
+        return ret;
+    }

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +31 -0
+
+    ctx->prepared = true;
+    return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct device *dev = &ctx->dsi->dev;
+    int ret;
+
+    if (!ctx->prepared)
+        return 0;
+
+    ret = visionox_r66451_off(ctx);
+    if (ret < 0)
+        dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+    ctx->prepared = false;
+    return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+    .clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,
+    .hdisplay = 1080,
+    .hsync_start = 1080 + 95,
+    .hsync_end = 1080 + 95 + 1,
+    .htotal = 1080 + 95 + 1 + 40,
Quoted 8 lines
Quoted 6 lines

+    .vdisplay = 2340,
+    .vsync_start = 2340 + 25,
+    .vsync_end = 2340 + 25 + 1,
+    .vtotal = 2340 + 25 + 1 + 4,
+    .width_mm = 0,
+    .height_mm = 0,

Please provide real values here.

Acked.

Quoted 52 lines
Quoted 40 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +39 -0
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct drm_dsc_picture_parameter_set pps;
+    int ret;
+
+    if (ctx->enabled)
+        return 0;
+
+    if (!dsi->dsc) {
+        dev_err(&dsi->dev, "DSC not attached to DSI\n");
+        return -ENODEV;
+    }
+
+    drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+    ret = mipi_dsi_picture_parameter_set(dsi, &pps);
+
+    ctx->enabled = true;
+
+    return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+    ctx->enabled = false;
+
+    return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+                    struct drm_connector *connector)
+{
+    struct drm_display_mode *mode;
+

drivers/gpu/drm/panel/panel-visionox-r66451.c line 260

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+    mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+    if (!mode)
+        return -ENOMEM;
+
+    drm_mode_set_name(mode);
+
+    mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+    connector->display_info.width_mm = mode->width_mm;
+    connector->display_info.height_mm = mode->height_mm;
+    drm_mode_probed_add(connector, mode);

Can we use drm_connector_helper_get_modes_fixed() instead?

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Acked.

Hi Dmitry,

Just wanted to follow up on this -- As Marijn mentioned in a separated thread, DRM_MODE_TYPE_DRIVER is not set within drm_connector_helper_get_modes_fixed(), and looking at the kernel docs, that's a required flag for this mode.

You can set this flag in the visionox_r66451_mode, can you not?

Sure, I can set it during initialization then; just didn't see a precedent for it in existing drivers.

Quoted 6 lines
Quoted 2 lines

Since I'm not able to set the *_TYPE_DRIVER flag before *_get_modes_fixed() is called, I'll stick to using the previous method of calling drm_mode_probed_add() directly in visionox_r66451_get_modes(). (FWIW, other drivers such as panel-visionox-vtdr6130, panel-truly-nt35597, and panel-visionox-rm69299 also don't use *_get_modes_fixed() and call drm_mode_probed_add() directly in their get_mode() implementations.)

That doesn't mean that we should increase the amount of the c&p code.

If I have time, I'try doing a rework of existing panel drivers.

Sounds good -- I think that would help get rid of a lot of duplicate code.

Thanks,

Jessica Zhang

Quoted 5 lines
Signature · 3 lines
-- 
With best wishes
Dmitry
#16 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

In reply to Dmitry Baryshkov
Quoted 159 lines · Dmitry Baryshkov
Quoted 145 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
  drivers/gpu/drm/panel/Kconfig                 |   8 +
  drivers/gpu/drm/panel/Makefile                |   1 +
  drivers/gpu/drm/panel/panel-visionox-r66451.c | 395 ++++++++++++++++++++++++++
  3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +8 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130
  	  Say Y here if you want to enable support for Visionox
  	  VTDR6130 1080x2400 AMOLED DSI panel.
 
+config DRM_PANEL_VISIONOX_R66451
+	tristate "Visionox R66451"
+	depends on OF
+	depends on DRM_MIPI_DSI
+	help
+	  Say Y here if you want to enable support for Visionox
+	  R66451 1080x2340 AMOLED DSI panel.
+
  config DRM_PANEL_WIDECHIPS_WS2401
  	tristate "Widechips WS2401 DPI panel driver"
  	depends on SPI && GPIOLIB
drivers/gpu/drm/panel/Makefile +1 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += panel-tpo-tpg110.o
  obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o
  obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o
  obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o
+obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o
  obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o
  obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +97 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+	struct drm_panel panel;
+	struct mipi_dsi_device *dsi;
+	struct gpio_desc *reset_gpio;
+	struct regulator_bulk_data supplies[2];
+	bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct drm_panel *panel)
+{
+	return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+	gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+	usleep_range(10000, 10100);
+	gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+	usleep_range(10000, 10100);
+	gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+	usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	struct device *dev = &dsi->dev;
+	int ret;
+
+	dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xc2,
+			       0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
+			       0x09, 0x3c);
+	mipi_dsi_dcs_write_seq(dsi, 0xd7,
+			       0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+			       0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+			       0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+	mipi_dsi_dcs_write_seq(dsi, 0xde,
+			       0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+			       0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02, 0x00, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+	mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+	mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xc4,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32);
+	mipi_dsi_dcs_write_seq(dsi, 0xcf,
+			       0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
+			       0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+			       0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+	mipi_dsi_dcs_write_seq(dsi, 0xd3,
+			       0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07,
+			       0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0,
+			       0x3c, 0x9c);
+	mipi_dsi_dcs_write_seq(dsi, 0xd7,
+			       0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+			       0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+			       0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+	mipi_dsi_dcs_write_seq(dsi, 0xd8,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a,
+			       0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
+			       0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+	mipi_dsi_dcs_write_seq(dsi, 0xdf,
+			       0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00,
+			       0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+	mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00, 0x39, 0x04, 0x09, 0x34);
+	mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);

drivers/gpu/drm/panel/panel-visionox-r66451.c line 107

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+	mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+	mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+	mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01);
+	mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+	mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+	mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+	mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
+	mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x04, 0x37);

Please use mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1);

Quoted 3 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 108

Quoted 1 line
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +1 -0
+	mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00, 0x09, 0x23);

mipi_dsi_dcs_set_page_address(dsi, 0, 2340 - 1);

Yes please, thanks for already pointing these two out.

Quoted 130 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 117

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -0
+
+	ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+		return ret;
+	}
+	msleep(120);
+
+	ret = mipi_dsi_dcs_set_display_on(dsi);

Should the mipi_dsi_dcs_set_display_on() (and maybe exit sleep mode) be a a part of _enable()? Correspondingly _off should IMO be a part of _disable callback().

drivers/gpu/drm/panel/panel-visionox-r66451.c line 122

Quoted 5 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+	if (ret < 0) {
+		dev_err(dev, "Failed on set display on: %d\n", ret);
+		return ret;
+	}
+	msleep(20);

Do we need to add here the following line?

dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

Quoted 79 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +79 -0
+
+	return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	struct device *dev = &dsi->dev;
+	int ret;
+
+	dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+	ret = mipi_dsi_dcs_set_display_off(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed to set display off: %d\n", ret);
+		return ret;
+	}
+	msleep(20);
+
+	ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+		return ret;
+	}
+	msleep(120);
+
+	return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(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)
+		return ret;
+
+	visionox_r66451_reset(ctx);
+
+	ret = visionox_r66451_on(ctx);
+	if (ret < 0) {
+		dev_err(dev, "Failed to initialize panel: %d\n", ret);
+		gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+		regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+		return ret;
+	}
+
+	ctx->prepared = true;
+	return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+	struct device *dev = &ctx->dsi->dev;
+	int ret;
+
+	if (!ctx->prepared)
+		return 0;
+
+	ret = visionox_r66451_off(ctx);
+	if (ret < 0)
+		dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+	gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+	regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+	ctx->prepared = false;
+	return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+	.clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,

drivers/gpu/drm/panel/panel-visionox-r66451.c line 211

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+	.hdisplay = 1080,
+	.hsync_start = 1080 + 95,
+	.hsync_end = 1080 + 95 + 1,
+	.htotal = 1080 + 95 + 1 + 40,
+	.vdisplay = 2340,
+	.vsync_start = 2340 + 25,
+	.vsync_end = 2340 + 25 + 1,
+	.vtotal = 2340 + 25 + 1 + 4,
+	.width_mm = 0,
+	.height_mm = 0,

Please provide real values here.

Quoted 11 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +11 -0
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	struct drm_dsc_picture_parameter_set pps;
+	int ret;
+
+	if (ctx->enabled)
+		return 0;
Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 230

Quoted 8 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +8 -0
+
+	if (!dsi->dsc) {
+		dev_err(&dsi->dev, "DSC not attached to DSI\n");
+		return -ENODEV;
+	}
+
+	drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+	ret = mipi_dsi_picture_parameter_set(dsi, &pps);

This ret value is unused.

Do we also need to call mipi_dsi_compression_mode() to enable compression? This also selects PPS table 1 (which is supposedly the default reset value, and the PPS that is uploaded by mipi_dsi_picture_parameter_set()). Note that it does set the algorithm to "VESA DSC Standard 1.1" but i am unsure if it makes a difference (docs for mipi_dsi_picture_parameter_set() say that it is "1.1" as well)

Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +24 -0
+
+	ctx->enabled = true;
+
+	return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+	ctx->enabled = false;
+
+	return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+				    struct drm_connector *connector)
+{
+	struct drm_display_mode *mode;
+
+	mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+	if (!mode)
+		return -ENOMEM;
+
Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 260

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+	drm_mode_set_name(mode);
+
+	mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+	connector->display_info.width_mm = mode->width_mm;
+	connector->display_info.height_mm = mode->height_mm;
+	drm_mode_probed_add(connector, mode);

Can we use drm_connector_helper_get_modes_fixed() instead?

This does not set DRM_MODE_TYPE_DRIVER though; is that preferred?

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +13 -0
+
+	return 1;
+}
+
+static const struct drm_panel_funcs visionox_r66451_funcs = {
+	.prepare = visionox_r66451_prepare,
+	.unprepare = visionox_r66451_unprepare,
+	.get_modes = visionox_r66451_get_modes,
+	.enable = visionox_r66451_enable,
+	.disable = visionox_r66451_disable,
+};
+
+static int visionox_r66451_bl_update_status(struct backlight_device *bl)
Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 278

Quoted 5 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+{
+	struct mipi_dsi_device *dsi = bl_get_data(bl);
+	u16 brightness = backlight_get_brightness(bl);
+
+	return mipi_dsi_dcs_set_display_brightness(dsi, cpu_to_le16(brightness));

mipi_dsi_dcs_set_display_brightness() already converts the brightness, so you don't need cpu_to_le16 here.

Tread carefully here: we've had the same issue and conversation on our Sony panels where this extra inversion is required. set_display_brightness() sends the bytes as little-endian to the panel (and it even assumes little-endian in get_display_brightness()) but the spec for 16-bit brightness values states that they have to be sent in big-endian. This is why c9d27c6be518b ("drm/mipi-dsi: Fix byte order of 16-bit DCS set/get brightness") added mipi_dsi_dcs_set_display_brightness_large().

Jessica, if you need to have the endian swap here (should be very easy to test with a real panel, but it should be given the max_brightness value being over 8 bits) please switch to the _large() variant.

Quoted 4 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 282

Quoted 4 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +4 -0
+}
+
+static const struct backlight_ops visionox_r66451_bl_ops = {
+	.update_status = visionox_r66451_bl_update_status,

Should this implement get_brightness?

Quoted 32 lines
Quoted 32 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +32 -0
+};
+
+static struct backlight_device *
+visionox_r66451_create_backlight(struct mipi_dsi_device *dsi)
+{
+	struct device *dev = &dsi->dev;
+	const struct backlight_properties props = {
+		.type = BACKLIGHT_RAW,
+		.brightness = 255,
+		.max_brightness = 4095,
+	};
+
+	return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+					      &visionox_r66451_bl_ops, &props);
+}
+
+static int visionox_r66451_probe(struct mipi_dsi_device *dsi)
+{
+	struct device *dev = &dsi->dev;
+	struct visionox_r66451 *ctx;
+	struct drm_dsc_config *dsc;
+	int ret = 0;
+
+	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return -ENOMEM;
+
+	dsc = devm_kzalloc(dev, sizeof(*dsc), GFP_KERNEL);
+	if (!dsc)
+		return -ENOMEM;
+
+	/* Set DSC params */
Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 322

Quoted 8 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +8 -0
+	dsc->dsc_version_major = 0x1;
+	dsc->dsc_version_minor = 0x2;
+
+	dsc->slice_height = 20;
+	dsc->slice_width = 540;
+	dsc->slice_count = 2;
+	dsc->bits_per_component = 8;
+	dsc->bits_per_pixel = 0x8 << 4;

What's the 0x for? bpc is also just "8" and not 0x8.

- Marijn

Quoted 79 lines
Quoted 74 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +73 -0
+	dsc->block_pred_enable = true;
+
+	dsi->dsc = dsc;
+
+	ctx->supplies[0].supply = "vddio";
+	ctx->supplies[1].supply = "vdd";
+
+	ret = devm_regulator_bulk_get(&dsi->dev, ARRAY_SIZE(ctx->supplies),
+			ctx->supplies);
+
+	if (ret < 0)
+		return ret;
+
+	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");
+
+	ctx->dsi = dsi;
+	mipi_dsi_set_drvdata(dsi, ctx);
+
+	dsi->lanes = 4;
+	dsi->format = MIPI_DSI_FMT_RGB888;
+	dsi->mode_flags = MIPI_DSI_MODE_LPM | MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+	drm_panel_init(&ctx->panel, dev, &visionox_r66451_funcs, DRM_MODE_CONNECTOR_DSI);
+	ctx->panel.backlight = visionox_r66451_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;
+}
+
+static void visionox_r66451_remove(struct mipi_dsi_device *dsi)
+{
+	struct visionox_r66451 *ctx = mipi_dsi_get_drvdata(dsi);
+	int ret;
+
+	ret = mipi_dsi_detach(dsi);
+	if (ret < 0)
+		dev_err(&dsi->dev, "Failed to detach DSI host: %d\n", ret);
+
+	drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id visionox_r66451_of_match[] = {
+	{.compatible = "visionox,r66451"},
+	{ /*sentinel*/ }
+};
+MODULE_DEVICE_TABLE(of, visionox_r66451_of_match);
+
+static struct mipi_dsi_driver visionox_r66451_driver = {
+	.probe = visionox_r66451_probe,
+	.remove = visionox_r66451_remove,
+	.driver = {
+		.name = "panel-visionox-r66451",
+		.of_match_table = visionox_r66451_of_match,
+	},
+};
+
+module_mipi_dsi_driver(visionox_r66451_driver);
+
+MODULE_AUTHOR("Jessica Zhang <[email protected]>");
+MODULE_DESCRIPTION("Panel driver for the Visionox R66451 AMOLED DSI panel");
+MODULE_LICENSE("GPL");
Signature · 2 lines
With best wishes
Dmitry
#17 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

Quoted 298 lines · Marijn Suijten
Quoted 159 lines · Dmitry Baryshkov
Quoted 145 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
   drivers/gpu/drm/panel/Kconfig                 |   8 +
   drivers/gpu/drm/panel/Makefile                |   1 +
   drivers/gpu/drm/panel/panel-visionox-r66451.c | 395 ++++++++++++++++++++++++++
   3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +8 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130
   	  Say Y here if you want to enable support for Visionox
   	  VTDR6130 1080x2400 AMOLED DSI panel.
 
+config DRM_PANEL_VISIONOX_R66451
+	tristate "Visionox R66451"
+	depends on OF
+	depends on DRM_MIPI_DSI
+	help
+	  Say Y here if you want to enable support for Visionox
+	  R66451 1080x2340 AMOLED DSI panel.
+
   config DRM_PANEL_WIDECHIPS_WS2401
   	tristate "Widechips WS2401 DPI panel driver"
   	depends on SPI && GPIOLIB
drivers/gpu/drm/panel/Makefile +1 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += panel-tpo-tpg110.o
   obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o
   obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o
   obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o
+obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o
   obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o
   obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +97 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+	struct drm_panel panel;
+	struct mipi_dsi_device *dsi;
+	struct gpio_desc *reset_gpio;
+	struct regulator_bulk_data supplies[2];
+	bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct drm_panel *panel)
+{
+	return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+	gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+	usleep_range(10000, 10100);
+	gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+	usleep_range(10000, 10100);
+	gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+	usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	struct device *dev = &dsi->dev;
+	int ret;
+
+	dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xc2,
+			       0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
+			       0x09, 0x3c);
+	mipi_dsi_dcs_write_seq(dsi, 0xd7,
+			       0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+			       0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+			       0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+	mipi_dsi_dcs_write_seq(dsi, 0xde,
+			       0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+			       0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02, 0x00, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+	mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+	mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xc4,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32);
+	mipi_dsi_dcs_write_seq(dsi, 0xcf,
+			       0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
+			       0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+			       0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+	mipi_dsi_dcs_write_seq(dsi, 0xd3,
+			       0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07,
+			       0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0,
+			       0x3c, 0x9c);
+	mipi_dsi_dcs_write_seq(dsi, 0xd7,
+			       0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+			       0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+			       0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+	mipi_dsi_dcs_write_seq(dsi, 0xd8,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a,
+			       0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
+			       0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+	mipi_dsi_dcs_write_seq(dsi, 0xdf,
+			       0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00,
+			       0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+	mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00, 0x39, 0x04, 0x09, 0x34);
+	mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);

drivers/gpu/drm/panel/panel-visionox-r66451.c line 107

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+	mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+	mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+	mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01);
+	mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+	mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+	mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+	mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
+	mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x04, 0x37);

Please use mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1);

Quoted 3 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 108

Quoted 1 line
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +1 -0
+	mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00, 0x09, 0x23);

mipi_dsi_dcs_set_page_address(dsi, 0, 2340 - 1);

Yes please, thanks for already pointing these two out.

Quoted 132 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 117

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -0
+
+	ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+		return ret;
+	}
+	msleep(120);
+
+	ret = mipi_dsi_dcs_set_display_on(dsi);

Should the mipi_dsi_dcs_set_display_on() (and maybe exit sleep mode) be a a part of _enable()? Correspondingly _off should IMO be a part of _disable callback().

drivers/gpu/drm/panel/panel-visionox-r66451.c line 122

Quoted 5 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+	if (ret < 0) {
+		dev_err(dev, "Failed on set display on: %d\n", ret);
+		return ret;
+	}
+	msleep(20);

Do we need to add here the following line?

dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

Quoted 79 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +79 -0
+
+	return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	struct device *dev = &dsi->dev;
+	int ret;
+
+	dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+	ret = mipi_dsi_dcs_set_display_off(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed to set display off: %d\n", ret);
+		return ret;
+	}
+	msleep(20);
+
+	ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+		return ret;
+	}
+	msleep(120);
+
+	return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(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)
+		return ret;
+
+	visionox_r66451_reset(ctx);
+
+	ret = visionox_r66451_on(ctx);
+	if (ret < 0) {
+		dev_err(dev, "Failed to initialize panel: %d\n", ret);
+		gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+		regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+		return ret;
+	}
+
+	ctx->prepared = true;
+	return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+	struct device *dev = &ctx->dsi->dev;
+	int ret;
+
+	if (!ctx->prepared)
+		return 0;
+
+	ret = visionox_r66451_off(ctx);
+	if (ret < 0)
+		dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+	gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+	regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+	ctx->prepared = false;
+	return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+	.clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,

drivers/gpu/drm/panel/panel-visionox-r66451.c line 211

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+	.hdisplay = 1080,
+	.hsync_start = 1080 + 95,
+	.hsync_end = 1080 + 95 + 1,
+	.htotal = 1080 + 95 + 1 + 40,
+	.vdisplay = 2340,
+	.vsync_start = 2340 + 25,
+	.vsync_end = 2340 + 25 + 1,
+	.vtotal = 2340 + 25 + 1 + 4,
+	.width_mm = 0,
+	.height_mm = 0,

Please provide real values here.

Quoted 13 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +13 -0
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	struct drm_dsc_picture_parameter_set pps;
+	int ret;
+
+	if (ctx->enabled)
+		return 0;
+
+	if (!dsi->dsc) {
Quoted 8 lines
Quoted 6 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 230

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+		dev_err(&dsi->dev, "DSC not attached to DSI\n");
+		return -ENODEV;
+	}
+
+	drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+	ret = mipi_dsi_picture_parameter_set(dsi, &pps);

This ret value is unused.

Hi Marijn,

Acked.

Quoted 3 lines

Do we also need to call mipi_dsi_compression_mode() to enable compression?

From my understanding, DSC is enabled by default for this panel, so it's not necessary to explicitly set it.

Quoted 5 lines

This also selects PPS table 1 (which is supposedly the default reset value, and the PPS that is uploaded by mipi_dsi_picture_parameter_set()). Note that it does set the algorithm to "VESA DSC Standard 1.1" but i am unsure if it makes a difference (docs for mipi_dsi_picture_parameter_set() say that it is "1.1" as well)

We noticed the same thing when trying to debug an unrelated panel issue. FWIW, the raw PPS values being sent to the panel are correct and it's not breaking DSC for us.

Quoted 67 lines
Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +24 -0
+
+	ctx->enabled = true;
+
+	return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+	ctx->enabled = false;
+
+	return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+				    struct drm_connector *connector)
+{
+	struct drm_display_mode *mode;
+
+	mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+	if (!mode)
+		return -ENOMEM;
+
Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 260

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+	drm_mode_set_name(mode);
+
+	mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+	connector->display_info.width_mm = mode->width_mm;
+	connector->display_info.height_mm = mode->height_mm;
+	drm_mode_probed_add(connector, mode);

Can we use drm_connector_helper_get_modes_fixed() instead?

This does not set DRM_MODE_TYPE_DRIVER though; is that preferred?

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +13 -0
+
+	return 1;
+}
+
+static const struct drm_panel_funcs visionox_r66451_funcs = {
+	.prepare = visionox_r66451_prepare,
+	.unprepare = visionox_r66451_unprepare,
+	.get_modes = visionox_r66451_get_modes,
+	.enable = visionox_r66451_enable,
+	.disable = visionox_r66451_disable,
+};
+
+static int visionox_r66451_bl_update_status(struct backlight_device *bl)
Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 278

Quoted 5 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+{
+	struct mipi_dsi_device *dsi = bl_get_data(bl);
+	u16 brightness = backlight_get_brightness(bl);
+
+	return mipi_dsi_dcs_set_display_brightness(dsi, cpu_to_le16(brightness));

mipi_dsi_dcs_set_display_brightness() already converts the brightness, so you don't need cpu_to_le16 here.

Tread carefully here: we've had the same issue and conversation on our Sony panels where this extra inversion is required. set_display_brightness() sends the bytes as little-endian to the panel (and it even assumes little-endian in get_display_brightness()) but the spec for 16-bit brightness values states that they have to be sent in big-endian. This is why c9d27c6be518b ("drm/mipi-dsi: Fix byte order of 16-bit DCS set/get brightness") added mipi_dsi_dcs_set_display_brightness_large().

Quoted 3 lines

Jessica, if you need to have the endian swap here (should be very easy to test with a real panel, but it should be given the max_brightness value being over 8 bits) please switch to the _large() variant.

Got it, thanks for the heads up!

Quoted 7 lines
Quoted 5 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 282

Quoted 5 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +4 -0
+}
+
+static const struct backlight_ops visionox_r66451_bl_ops = {
+	.update_status = visionox_r66451_bl_update_status,

Should this implement get_brightness?

I don't believe so. As far as I know, get_brightness() is an optional op for if the panel has a special HW readback for getting the brightness value, and this panel doesn't have that. So the default behavior of getting the current brightness property value should be fine.

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +34 -0
+};
+
+static struct backlight_device *
+visionox_r66451_create_backlight(struct mipi_dsi_device *dsi)
+{
+	struct device *dev = &dsi->dev;
+	const struct backlight_properties props = {
+		.type = BACKLIGHT_RAW,
+		.brightness = 255,
+		.max_brightness = 4095,
+	};
+
+	return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+					      &visionox_r66451_bl_ops, &props);
+}
+
+static int visionox_r66451_probe(struct mipi_dsi_device *dsi)
+{
+	struct device *dev = &dsi->dev;
+	struct visionox_r66451 *ctx;
+	struct drm_dsc_config *dsc;
+	int ret = 0;
+
+	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return -ENOMEM;
+
+	dsc = devm_kzalloc(dev, sizeof(*dsc), GFP_KERNEL);
+	if (!dsc)
+		return -ENOMEM;
+
+	/* Set DSC params */
+	dsc->dsc_version_major = 0x1;
+	dsc->dsc_version_minor = 0x2;
Quoted 8 lines
Quoted 6 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 322

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+
+	dsc->slice_height = 20;
+	dsc->slice_width = 540;
+	dsc->slice_count = 2;
+	dsc->bits_per_component = 8;
+	dsc->bits_per_pixel = 0x8 << 4;

What's the 0x for? bpc is also just "8" and not 0x8.

Is there a functional difference between 0x8 vs 8? I can drop the "0x" if you prefer it as decimal instead of hex.

Thanks,

Jessica Zhang

Quoted 82 lines

- Marijn

Quoted 79 lines
Quoted 74 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +73 -0
+	dsc->block_pred_enable = true;
+
+	dsi->dsc = dsc;
+
+	ctx->supplies[0].supply = "vddio";
+	ctx->supplies[1].supply = "vdd";
+
+	ret = devm_regulator_bulk_get(&dsi->dev, ARRAY_SIZE(ctx->supplies),
+			ctx->supplies);
+
+	if (ret < 0)
+		return ret;
+
+	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");
+
+	ctx->dsi = dsi;
+	mipi_dsi_set_drvdata(dsi, ctx);
+
+	dsi->lanes = 4;
+	dsi->format = MIPI_DSI_FMT_RGB888;
+	dsi->mode_flags = MIPI_DSI_MODE_LPM | MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+	drm_panel_init(&ctx->panel, dev, &visionox_r66451_funcs, DRM_MODE_CONNECTOR_DSI);
+	ctx->panel.backlight = visionox_r66451_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;
+}
+
+static void visionox_r66451_remove(struct mipi_dsi_device *dsi)
+{
+	struct visionox_r66451 *ctx = mipi_dsi_get_drvdata(dsi);
+	int ret;
+
+	ret = mipi_dsi_detach(dsi);
+	if (ret < 0)
+		dev_err(&dsi->dev, "Failed to detach DSI host: %d\n", ret);
+
+	drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id visionox_r66451_of_match[] = {
+	{.compatible = "visionox,r66451"},
+	{ /*sentinel*/ }
+};
+MODULE_DEVICE_TABLE(of, visionox_r66451_of_match);
+
+static struct mipi_dsi_driver visionox_r66451_driver = {
+	.probe = visionox_r66451_probe,
+	.remove = visionox_r66451_remove,
+	.driver = {
+		.name = "panel-visionox-r66451",
+		.of_match_table = visionox_r66451_of_match,
+	},
+};
+
+module_mipi_dsi_driver(visionox_r66451_driver);
+
+MODULE_AUTHOR("Jessica Zhang <[email protected]>");
+MODULE_DESCRIPTION("Panel driver for the Visionox R66451 AMOLED DSI panel");
+MODULE_LICENSE("GPL");
Signature · 2 lines
With best wishes
Dmitry
#18 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

Quoted 426 lines · Jessica Zhang
Quoted 326 lines · Marijn Suijten
Quoted 185 lines · Dmitry Baryshkov
Quoted 173 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
   drivers/gpu/drm/panel/Kconfig                 |   8 + drivers/gpu/drm/panel/Makefile                |   1 + drivers/gpu/drm/panel/panel-visionox-r66451.c | 395
++++++++++++++++++++++++++

   3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +0 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130

         Say Y here if you want to enable support for Visionox VTDR6130 1080x2400 AMOLED DSI panel.

drivers/gpu/drm/panel/Kconfig +8 -0
+config DRM_PANEL_VISIONOX_R66451
+    tristate "Visionox R66451"
+    depends on OF
+    depends on DRM_MIPI_DSI
+    help
+      Say Y here if you want to enable support for Visionox
+      R66451 1080x2340 AMOLED DSI panel.
+

   config DRM_PANEL_WIDECHIPS_WS2401 tristate "Widechips WS2401 DPI panel driver" depends on SPI && GPIOLIB

drivers/gpu/drm/panel/Makefile +0 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += 

panel-tpo-tpg110.o
   obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o +obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +2 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights 

reserved.

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +25 -0
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+    struct drm_panel panel;
+    struct mipi_dsi_device *dsi;
+    struct gpio_desc *reset_gpio;
+    struct regulator_bulk_data supplies[2];
+    bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct 

drm_panel *panel)

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +25 -0
+{
+    return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc2,
+                   0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 

0x00,
+                   0x09, 0x3c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a); +    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xde,
+                   0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+                   0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc4,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32); +    mipi_dsi_dcs_write_seq(dsi, 0xcf,
+                   0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
+                   0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+                   0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+    mipi_dsi_dcs_write_seq(dsi, 0xd3,
+                   0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07,
+                   0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0,
+                   0x3c, 0x9c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a); +    mipi_dsi_dcs_write_seq(dsi, 0xd8,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a,
+                   0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
+                   0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf,
+                   0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00, 0x39, 0x04, 0x09, 0x34);
+    mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00);

Quoted 8 lines

+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01); +    mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+    mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK); +    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x04, 0x37);

Please use mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1);

Quoted 4 lines
Quoted 2 lines

+    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00, 0x09, 0x23);

mipi_dsi_dcs_set_page_address(dsi, 0, 2340 - 1);

Yes please, thanks for already pointing these two out.

Quoted 133 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 117

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -0
+
+    ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    ret = mipi_dsi_dcs_set_display_on(dsi);

Should the mipi_dsi_dcs_set_display_on() (and maybe exit sleep mode) be a a part of _enable()? Correspondingly _off should IMO be a part of _disable callback().

Quoted 5 lines

+    if (ret < 0) {
+        dev_err(dev, "Failed on set display on: %d\n", ret); +        return ret;
+    }
+    msleep(20);

Do we need to add here the following line?

dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

Quoted 80 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +50 -0
+
+    return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+    ret = mipi_dsi_dcs_set_display_off(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to set display off: %d\n", ret);
+        return ret;
+    }
+    msleep(20);
+
+    ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(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)
+        return ret;
+
+    visionox_r66451_reset(ctx);
+
+    ret = visionox_r66451_on(ctx);
+    if (ret < 0) {
+        dev_err(dev, "Failed to initialize panel: %d\n", ret);
+        gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+        regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), 

ctx->supplies);
+        return ret;
+    }

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +27 -0
+
+    ctx->prepared = true;
+    return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct device *dev = &ctx->dsi->dev;
+    int ret;
+
+    if (!ctx->prepared)
+        return 0;
+
+    ret = visionox_r66451_off(ctx);
+    if (ret < 0)
+        dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+    ctx->prepared = false;
+    return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+    .clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,

drivers/gpu/drm/panel/panel-visionox-r66451.c line 211

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+    .hdisplay = 1080,
+    .hsync_start = 1080 + 95,
+    .hsync_end = 1080 + 95 + 1,
+    .htotal = 1080 + 95 + 1 + 40,
+    .vdisplay = 2340,
+    .vsync_start = 2340 + 25,
+    .vsync_end = 2340 + 25 + 1,
+    .vtotal = 2340 + 25 + 1 + 4,
+    .width_mm = 0,
+    .height_mm = 0,

Please provide real values here.

Quoted 13 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +13 -0
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct drm_dsc_picture_parameter_set pps;
+    int ret;
+
+    if (ctx->enabled)
+        return 0;
+
+    if (!dsi->dsc) {
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

+        dev_err(&dsi->dev, "DSC not attached to DSI\n"); +        return -ENODEV;
+    }
+
+    drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+    ret = mipi_dsi_picture_parameter_set(dsi, &pps);

This ret value is unused.

Hi Marijn,

Acked.

Quoted 3 lines

Do we also need to call mipi_dsi_compression_mode() to enable compression?

From my understanding, DSC is enabled by default for this panel, so
it's not necessary to explicitly set it.

Quoted 5 lines

This also selects PPS table 1 (which is supposedly the default reset value, and the PPS that is uploaded by mipi_dsi_picture_parameter_set()).  Note that it does set the algorithm to "VESA DSC Standard 1.1" but i am unsure if it makes a difference (docs for mipi_dsi_picture_parameter_set() say that it is "1.1" as well)

We noticed the same thing when trying to debug an unrelated panel issue. FWIW, the raw PPS values being sent to the panel are correct and it's not breaking DSC for us.

Quoted 69 lines
Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +24 -0
+
+    ctx->enabled = true;
+
+    return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+    ctx->enabled = false;
+
+    return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+                    struct drm_connector *connector)
+{
+    struct drm_display_mode *mode;
+
+    mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+    if (!mode)
+        return -ENOMEM;
+
Quoted 8 lines
Quoted 6 lines

+    drm_mode_set_name(mode);
+
+    mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; +    connector->display_info.width_mm = mode->width_mm; +    connector->display_info.height_mm = mode->height_mm; +    drm_mode_probed_add(connector, mode);

Can we use drm_connector_helper_get_modes_fixed() instead?

This does not set DRM_MODE_TYPE_DRIVER though; is that preferred?

Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +13 -0
+
+    return 1;
+}
+
+static const struct drm_panel_funcs visionox_r66451_funcs = {
+    .prepare = visionox_r66451_prepare,
+    .unprepare = visionox_r66451_unprepare,
+    .get_modes = visionox_r66451_get_modes,
+    .enable = visionox_r66451_enable,
+    .disable = visionox_r66451_disable,
+};
+
+static int visionox_r66451_bl_update_status(struct backlight_device 

*bl)
+{

Quoted 8 lines
Quoted 5 lines

+    struct mipi_dsi_device *dsi = bl_get_data(bl); +    u16 brightness = backlight_get_brightness(bl); +
+    return mipi_dsi_dcs_set_display_brightness(dsi, cpu_to_le16(brightness));

mipi_dsi_dcs_set_display_brightness() already converts the brightness, so you don't need cpu_to_le16 here.

Tread carefully here: we've had the same issue and conversation on our Sony panels where this extra inversion is required. set_display_brightness() sends the bytes as little-endian to the panel (and it even assumes little-endian in get_display_brightness()) but the spec for 16-bit brightness values states that they have to be sent in big-endian.  This is why c9d27c6be518b ("drm/mipi-dsi: Fix byte order of 16-bit DCS set/get brightness") added mipi_dsi_dcs_set_display_brightness_large().

Quoted 5 lines
Quoted 3 lines

Jessica, if you need to have the endian swap here (should be very easy to test with a real panel, but it should be given the max_brightness value being over 8 bits) please switch to the _large() variant.

Got it, thanks for the heads up!

Hi Marijn,

Just wanted to update this thread -- I've checked the backlight brightness values in the sysfs and it matches the value being given in the panel driver (255), so I think it should be fine to use *_set_display_brightness() without the _large() variant.

Thanks,

Jessica Zhang

Quoted 149 lines
Quoted 8 lines
Quoted 6 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 282

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +4 -0
+}
+
+static const struct backlight_ops visionox_r66451_bl_ops = {
+    .update_status = visionox_r66451_bl_update_status,

Should this implement get_brightness?

I don't believe so. As far as I know, get_brightness() is an optional op for if the panel has a special HW readback for getting the brightness value, and this panel doesn't have that. So the default behavior of getting the current brightness property value should be fine.

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +13 -0
+};
+
+static struct backlight_device *
+visionox_r66451_create_backlight(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    const struct backlight_properties props = {
+        .type = BACKLIGHT_RAW,
+        .brightness = 255,
+        .max_brightness = 4095,
+    };
+
+    return devm_backlight_device_register(dev, dev_name(dev), dev, 

dsi,
+                          &visionox_r66451_bl_ops, &props);

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +20 -0
+}
+
+static int visionox_r66451_probe(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    struct visionox_r66451 *ctx;
+    struct drm_dsc_config *dsc;
+    int ret = 0;
+
+    ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+    if (!ctx)
+        return -ENOMEM;
+
+    dsc = devm_kzalloc(dev, sizeof(*dsc), GFP_KERNEL);
+    if (!dsc)
+        return -ENOMEM;
+
+    /* Set DSC params */
+    dsc->dsc_version_major = 0x1;
+    dsc->dsc_version_minor = 0x2;
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

+
+    dsc->slice_height = 20;
+    dsc->slice_width = 540;
+    dsc->slice_count = 2;
+    dsc->bits_per_component = 8;
+    dsc->bits_per_pixel = 0x8 << 4;

What's the 0x for?  bpc is also just "8" and not 0x8.

Is there a functional difference between 0x8 vs 8? I can drop the "0x" if you prefer it as decimal instead of hex.

Thanks,

Jessica Zhang

Quoted 87 lines

- Marijn

Quoted 84 lines
Quoted 79 lines

+    dsc->block_pred_enable = true;

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +7 -0
+
+    dsi->dsc = dsc;
+
+    ctx->supplies[0].supply = "vddio";
+    ctx->supplies[1].supply = "vdd";
+
+    ret = devm_regulator_bulk_get(&dsi->dev, 

ARRAY_SIZE(ctx->supplies),
+            ctx->supplies);

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +7 -0
+
+    if (ret < 0)
+        return ret;
+
+    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");

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +7 -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_LPM | 

MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+    drm_panel_init(&ctx->panel, dev, &visionox_r66451_funcs, DRM_MODE_CONNECTOR_DSI);
+    ctx->panel.backlight = visionox_r66451_create_backlight(dsi); +    if (IS_ERR(ctx->panel.backlight))
+        return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight), +                "Failed to create backlight\n");

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +43 -0
+
+    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;
+}
+
+static void visionox_r66451_remove(struct mipi_dsi_device *dsi)
+{
+    struct visionox_r66451 *ctx = mipi_dsi_get_drvdata(dsi);
+    int ret;
+
+    ret = mipi_dsi_detach(dsi);
+    if (ret < 0)
+        dev_err(&dsi->dev, "Failed to detach DSI host: %d\n", ret);
+
+    drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id visionox_r66451_of_match[] = {
+    {.compatible = "visionox,r66451"},
+    { /*sentinel*/ }
+};
+MODULE_DEVICE_TABLE(of, visionox_r66451_of_match);
+
+static struct mipi_dsi_driver visionox_r66451_driver = {
+    .probe = visionox_r66451_probe,
+    .remove = visionox_r66451_remove,
+    .driver = {
+        .name = "panel-visionox-r66451",
+        .of_match_table = visionox_r66451_of_match,
+    },
+};
+
+module_mipi_dsi_driver(visionox_r66451_driver);
+
+MODULE_AUTHOR("Jessica Zhang <[email protected]>");
+MODULE_DESCRIPTION("Panel driver for the Visionox R66451 AMOLED DSI 

panel");
+MODULE_LICENSE("GPL");

Signature · 2 lines
With best wishes
Dmitry
maintainer
#19 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

Quoted 401 lines · Jessica Zhang
Quoted 398 lines · Jessica Zhang
Quoted 297 lines · Marijn Suijten
Quoted 158 lines · Dmitry Baryshkov
Quoted 144 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
   drivers/gpu/drm/panel/Kconfig                 |   8 + drivers/gpu/drm/panel/Makefile                |   1 + drivers/gpu/drm/panel/panel-visionox-r66451.c | 395 ++++++++++++++++++++++++++

   3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +0 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130

         Say Y here if you want to enable support for Visionox VTDR6130 1080x2400 AMOLED DSI panel.

drivers/gpu/drm/panel/Kconfig +8 -0
+config DRM_PANEL_VISIONOX_R66451
+    tristate "Visionox R66451"
+    depends on OF
+    depends on DRM_MIPI_DSI
+    help
+      Say Y here if you want to enable support for Visionox
+      R66451 1080x2340 AMOLED DSI panel.
+

   config DRM_PANEL_WIDECHIPS_WS2401 tristate "Widechips WS2401 DPI panel driver" depends on SPI && GPIOLIB

drivers/gpu/drm/panel/Makefile +0 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += panel-tpo-tpg110.o

   obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o +obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +97 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+    struct drm_panel panel;
+    struct mipi_dsi_device *dsi;
+    struct gpio_desc *reset_gpio;
+    struct regulator_bulk_data supplies[2];
+    bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct drm_panel *panel)
+{
+    return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc2,
+                   0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
+                   0x09, 0x3c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xde,
+                   0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+                   0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc4,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32);
+    mipi_dsi_dcs_write_seq(dsi, 0xcf,
+                   0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
+                   0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+                   0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+    mipi_dsi_dcs_write_seq(dsi, 0xd3,
+                   0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07,
+                   0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0,
+                   0x3c, 0x9c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+    mipi_dsi_dcs_write_seq(dsi, 0xd8,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a,
+                   0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
+                   0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf,
+                   0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00, 0x39, 0x04, 0x09, 0x34);
+    mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);

drivers/gpu/drm/panel/panel-visionox-r66451.c line 107

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01);
+    mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+    mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
+    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x04, 0x37);

Please use mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1);

Quoted 3 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 108

Quoted 1 line
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +1 -0
+    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00, 0x09, 0x23);

mipi_dsi_dcs_set_page_address(dsi, 0, 2340 - 1);

Yes please, thanks for already pointing these two out.

Quoted 132 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 117

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -0
+
+    ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    ret = mipi_dsi_dcs_set_display_on(dsi);

Should the mipi_dsi_dcs_set_display_on() (and maybe exit sleep mode) be a a part of _enable()? Correspondingly _off should IMO be a part of _disable callback().

drivers/gpu/drm/panel/panel-visionox-r66451.c line 122

Quoted 5 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+    if (ret < 0) {
+        dev_err(dev, "Failed on set display on: %d\n", ret);
+        return ret;
+    }
+    msleep(20);

Do we need to add here the following line?

dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

Quoted 79 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +79 -0
+
+    return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+    ret = mipi_dsi_dcs_set_display_off(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to set display off: %d\n", ret);
+        return ret;
+    }
+    msleep(20);
+
+    ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(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)
+        return ret;
+
+    visionox_r66451_reset(ctx);
+
+    ret = visionox_r66451_on(ctx);
+    if (ret < 0) {
+        dev_err(dev, "Failed to initialize panel: %d\n", ret);
+        gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+        regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+        return ret;
+    }
+
+    ctx->prepared = true;
+    return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct device *dev = &ctx->dsi->dev;
+    int ret;
+
+    if (!ctx->prepared)
+        return 0;
+
+    ret = visionox_r66451_off(ctx);
+    if (ret < 0)
+        dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+    ctx->prepared = false;
+    return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+    .clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,

drivers/gpu/drm/panel/panel-visionox-r66451.c line 211

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+    .hdisplay = 1080,
+    .hsync_start = 1080 + 95,
+    .hsync_end = 1080 + 95 + 1,
+    .htotal = 1080 + 95 + 1 + 40,
+    .vdisplay = 2340,
+    .vsync_start = 2340 + 25,
+    .vsync_end = 2340 + 25 + 1,
+    .vtotal = 2340 + 25 + 1 + 4,
+    .width_mm = 0,
+    .height_mm = 0,

Please provide real values here.

Quoted 13 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +13 -0
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct drm_dsc_picture_parameter_set pps;
+    int ret;
+
+    if (ctx->enabled)
+        return 0;
+
+    if (!dsi->dsc) {
Quoted 8 lines
Quoted 6 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 230

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+        dev_err(&dsi->dev, "DSC not attached to DSI\n");
+        return -ENODEV;
+    }
+
+    drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+    ret = mipi_dsi_picture_parameter_set(dsi, &pps);

This ret value is unused.

Hi Marijn,

Acked.

Quoted 3 lines

Do we also need to call mipi_dsi_compression_mode() to enable compression?

 From my understanding, DSC is enabled by default for this panel, so it's not necessary to explicitly set it.

Quoted 5 lines

This also selects PPS table 1 (which is supposedly the default reset value, and the PPS that is uploaded by mipi_dsi_picture_parameter_set()).  Note that it does set the algorithm to "VESA DSC Standard 1.1" but i am unsure if it makes a difference (docs for mipi_dsi_picture_parameter_set() say that it is "1.1" as well)

We noticed the same thing when trying to debug an unrelated panel issue. FWIW, the raw PPS values being sent to the panel are correct and it's not breaking DSC for us.

Quoted 70 lines
Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +24 -0
+
+    ctx->enabled = true;
+
+    return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+    ctx->enabled = false;
+
+    return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+                    struct drm_connector *connector)
+{
+    struct drm_display_mode *mode;
+
+    mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+    if (!mode)
+        return -ENOMEM;
+
Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 260

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+    drm_mode_set_name(mode);
+
+    mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+    connector->display_info.width_mm = mode->width_mm;
+    connector->display_info.height_mm = mode->height_mm;
+    drm_mode_probed_add(connector, mode);

Can we use drm_connector_helper_get_modes_fixed() instead?

This does not set DRM_MODE_TYPE_DRIVER though; is that preferred?

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +13 -0
+
+    return 1;
+}
+
+static const struct drm_panel_funcs visionox_r66451_funcs = {
+    .prepare = visionox_r66451_prepare,
+    .unprepare = visionox_r66451_unprepare,
+    .get_modes = visionox_r66451_get_modes,
+    .enable = visionox_r66451_enable,
+    .disable = visionox_r66451_disable,
+};
+
+static int visionox_r66451_bl_update_status(struct backlight_device *bl)
Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 278

Quoted 5 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+{
+    struct mipi_dsi_device *dsi = bl_get_data(bl);
+    u16 brightness = backlight_get_brightness(bl);
+
+    return mipi_dsi_dcs_set_display_brightness(dsi, cpu_to_le16(brightness));

mipi_dsi_dcs_set_display_brightness() already converts the brightness, so you don't need cpu_to_le16 here.

Tread carefully here: we've had the same issue and conversation on our Sony panels where this extra inversion is required. set_display_brightness() sends the bytes as little-endian to the panel (and it even assumes little-endian in get_display_brightness()) but the spec for 16-bit brightness values states that they have to be sent in big-endian.  This is why c9d27c6be518b ("drm/mipi-dsi: Fix byte order of 16-bit DCS set/get brightness") added mipi_dsi_dcs_set_display_brightness_large().

Jessica, if you need to have the endian swap here (should be very easy to test with a real panel, but it should be given the max_brightness value being over 8 bits) please switch to the _large() variant.

Quoted 5 lines
Quoted 1 line

Got it, thanks for the heads up!

Hi Marijn,

Just wanted to update this thread -- I've checked the backlight brightness values in the sysfs and it matches the value being given in the panel driver (255), so I think it should be fine to use *_set_display_brightness() without the _large() variant.

Sure, I was also misleaded by you using cpu_to_le16() but as Dmitry said it's already done in mipi_dsi_dcs_set_display_brightness() and a no-op on LE arm64 platforms anyway.

Neil

Quoted 148 lines

Thanks,

Jessica Zhang

Quoted 143 lines
Quoted 8 lines
Quoted 6 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 282

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +4 -0
+}
+
+static const struct backlight_ops visionox_r66451_bl_ops = {
+    .update_status = visionox_r66451_bl_update_status,

Should this implement get_brightness?

I don't believe so. As far as I know, get_brightness() is an optional op for if the panel has a special HW readback for getting the brightness value, and this panel doesn't have that. So the default behavior of getting the current brightness property value should be fine.

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +34 -0
+};
+
+static struct backlight_device *
+visionox_r66451_create_backlight(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    const struct backlight_properties props = {
+        .type = BACKLIGHT_RAW,
+        .brightness = 255,
+        .max_brightness = 4095,
+    };
+
+    return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+                          &visionox_r66451_bl_ops, &props);
+}
+
+static int visionox_r66451_probe(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    struct visionox_r66451 *ctx;
+    struct drm_dsc_config *dsc;
+    int ret = 0;
+
+    ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+    if (!ctx)
+        return -ENOMEM;
+
+    dsc = devm_kzalloc(dev, sizeof(*dsc), GFP_KERNEL);
+    if (!dsc)
+        return -ENOMEM;
+
+    /* Set DSC params */
+    dsc->dsc_version_major = 0x1;
+    dsc->dsc_version_minor = 0x2;
Quoted 8 lines
Quoted 6 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 322

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+
+    dsc->slice_height = 20;
+    dsc->slice_width = 540;
+    dsc->slice_count = 2;
+    dsc->bits_per_component = 8;
+    dsc->bits_per_pixel = 0x8 << 4;

What's the 0x for?  bpc is also just "8" and not 0x8.

Is there a functional difference between 0x8 vs 8? I can drop the "0x" if you prefer it as decimal instead of hex.

Thanks,

Jessica Zhang

Quoted 82 lines

- Marijn

Quoted 79 lines
Quoted 74 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +73 -0
+    dsc->block_pred_enable = true;
+
+    dsi->dsc = dsc;
+
+    ctx->supplies[0].supply = "vddio";
+    ctx->supplies[1].supply = "vdd";
+
+    ret = devm_regulator_bulk_get(&dsi->dev, ARRAY_SIZE(ctx->supplies),
+            ctx->supplies);
+
+    if (ret < 0)
+        return ret;
+
+    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");
+
+    ctx->dsi = dsi;
+    mipi_dsi_set_drvdata(dsi, ctx);
+
+    dsi->lanes = 4;
+    dsi->format = MIPI_DSI_FMT_RGB888;
+    dsi->mode_flags = MIPI_DSI_MODE_LPM | MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+    drm_panel_init(&ctx->panel, dev, &visionox_r66451_funcs, DRM_MODE_CONNECTOR_DSI);
+    ctx->panel.backlight = visionox_r66451_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;
+}
+
+static void visionox_r66451_remove(struct mipi_dsi_device *dsi)
+{
+    struct visionox_r66451 *ctx = mipi_dsi_get_drvdata(dsi);
+    int ret;
+
+    ret = mipi_dsi_detach(dsi);
+    if (ret < 0)
+        dev_err(&dsi->dev, "Failed to detach DSI host: %d\n", ret);
+
+    drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id visionox_r66451_of_match[] = {
+    {.compatible = "visionox,r66451"},
+    { /*sentinel*/ }
+};
+MODULE_DEVICE_TABLE(of, visionox_r66451_of_match);
+
+static struct mipi_dsi_driver visionox_r66451_driver = {
+    .probe = visionox_r66451_probe,
+    .remove = visionox_r66451_remove,
+    .driver = {
+        .name = "panel-visionox-r66451",
+        .of_match_table = visionox_r66451_of_match,
+    },
+};
+
+module_mipi_dsi_driver(visionox_r66451_driver);
+
+MODULE_AUTHOR("Jessica Zhang <[email protected]>");
+MODULE_DESCRIPTION("Panel driver for the Visionox R66451 AMOLED DSI panel");
+MODULE_LICENSE("GPL");
Signature · 2 lines
With best wishes
Dmitry
#20 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

On 2023-05-26 09:32:45, Neil Armstrong wrote:
<snip>

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 9 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 278

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+static int visionox_r66451_bl_update_status(struct backlight_device *bl)
+{
+    struct mipi_dsi_device *dsi = bl_get_data(bl);
+    u16 brightness = backlight_get_brightness(bl);
+
+    return mipi_dsi_dcs_set_display_brightness(dsi, cpu_to_le16(brightness));

mipi_dsi_dcs_set_display_brightness() already converts the brightness, so you don't need cpu_to_le16 here.

Tread carefully here: we've had the same issue and conversation on our Sony panels where this extra inversion is required. set_display_brightness() sends the bytes as little-endian to the panel (and it even assumes little-endian in get_display_brightness()) but the spec for 16-bit brightness values states that they have to be sent in big-endian.  This is why c9d27c6be518b ("drm/mipi-dsi: Fix byte order of 16-bit DCS set/get brightness") added mipi_dsi_dcs_set_display_brightness_large().

Jessica, if you need to have the endian swap here (should be very easy to test with a real panel, but it should be given the max_brightness value being over 8 bits) please switch to the _large() variant.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Got it, thanks for the heads up!

Hi Marijn,

Just wanted to update this thread -- I've checked the backlight brightness values in the sysfs and it matches the value being given in the panel driver (255), so I think it should be fine to use *_set_display_brightness() without the _large() variant.

Sure, I was also misleaded by you using cpu_to_le16() but as Dmitry said it's already done in mipi_dsi_dcs_set_display_brightness() and a no-op on LE arm64 platforms anyway.

Yuck, right, it's cpu_to_le16 here and not cpu_to_be16. @Jessica, can you please remove this misleading conversion? mipi_dsi_dcs_set_display_brightness() takes a native u16, not a specific __le16.

- Marijn

#21 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

Quoted 31 lines · Marijn Suijten

On 2023-05-26 09:32:45, Neil Armstrong wrote:
<snip>

Quoted 29 lines
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
Quoted 9 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+static int visionox_r66451_bl_update_status(struct backlight_device *bl)
+{
+    struct mipi_dsi_device *dsi = bl_get_data(bl);
+    u16 brightness = backlight_get_brightness(bl);
+
+    return mipi_dsi_dcs_set_display_brightness(dsi, cpu_to_le16(brightness));

mipi_dsi_dcs_set_display_brightness() already converts the brightness, so you don't need cpu_to_le16 here.

Tread carefully here: we've had the same issue and conversation on our Sony panels where this extra inversion is required. set_display_brightness() sends the bytes as little-endian to the panel (and it even assumes little-endian in get_display_brightness()) but the spec for 16-bit brightness values states that they have to be sent in big-endian.  This is why c9d27c6be518b ("drm/mipi-dsi: Fix byte order of 16-bit DCS set/get brightness") added mipi_dsi_dcs_set_display_brightness_large().

Quoted 5 lines
Quoted 3 lines

Jessica, if you need to have the endian swap here (should be very easy to test with a real panel, but it should be given the max_brightness value being over 8 bits) please switch to the _large() variant.

Got it, thanks for the heads up!

Hi Marijn,

Just wanted to update this thread -- I've checked the backlight brightness values in the sysfs and it matches the value being given in the panel driver (255), so I think it should be fine to use *_set_display_brightness() without the _large() variant.

Quoted 7 lines
Quoted 2 lines

Sure, I was also misleaded by you using cpu_to_le16() but as Dmitry said it's already done in mipi_dsi_dcs_set_display_brightness() and a no-op on LE arm64 platforms anyway.

Yuck, right, it's cpu_to_le16 here and not cpu_to_be16. @Jessica, can you please remove this misleading conversion? mipi_dsi_dcs_set_display_brightness() takes a native u16, not a specific __le16.

Hi Marijn,

Acked, will drop the conversion.

Thanks,

Jessica Zhang

Quoted 2 lines

- Marijn

maintainer
#22 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

In reply to Dmitry Baryshkov
Quoted 162 lines · Dmitry Baryshkov
Quoted 144 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
  drivers/gpu/drm/panel/Kconfig                 |   8 + drivers/gpu/drm/panel/Makefile                |   1 + drivers/gpu/drm/panel/panel-visionox-r66451.c | 395 ++++++++++++++++++++++++++

  3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +0 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130

        Say Y here if you want to enable support for Visionox VTDR6130 1080x2400 AMOLED DSI panel.

drivers/gpu/drm/panel/Kconfig +8 -0
+config DRM_PANEL_VISIONOX_R66451
+    tristate "Visionox R66451"
+    depends on OF
+    depends on DRM_MIPI_DSI
+    help
+      Say Y here if you want to enable support for Visionox
+      R66451 1080x2340 AMOLED DSI panel.
+

  config DRM_PANEL_WIDECHIPS_WS2401 tristate "Widechips WS2401 DPI panel driver" depends on SPI && GPIOLIB

drivers/gpu/drm/panel/Makefile +0 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += panel-tpo-tpg110.o

  obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o +obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +97 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+    struct drm_panel panel;
+    struct mipi_dsi_device *dsi;
+    struct gpio_desc *reset_gpio;
+    struct regulator_bulk_data supplies[2];
+    bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct drm_panel *panel)
+{
+    return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc2,
+                   0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
+                   0x09, 0x3c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xde,
+                   0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+                   0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc4,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32);
+    mipi_dsi_dcs_write_seq(dsi, 0xcf,
+                   0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
+                   0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+                   0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+    mipi_dsi_dcs_write_seq(dsi, 0xd3,
+                   0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07,
+                   0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0,
+                   0x3c, 0x9c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+    mipi_dsi_dcs_write_seq(dsi, 0xd8,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a,
+                   0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
+                   0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf,
+                   0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00, 0x39, 0x04, 0x09, 0x34);
+    mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);

drivers/gpu/drm/panel/panel-visionox-r66451.c line 107

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01);
+    mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+    mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
+    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x04, 0x37);

Please use mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1);

drivers/gpu/drm/panel/panel-visionox-r66451.c line 108

Quoted 1 line
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +1 -0
+    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00, 0x09, 0x23);

mipi_dsi_dcs_set_page_address(dsi, 0, 2340 - 1);

Quoted 11 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 117

Quoted 9 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -0
+
+    ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    ret = mipi_dsi_dcs_set_display_on(dsi);

Should the mipi_dsi_dcs_set_display_on() (and maybe exit sleep mode) be a a part of _enable()? Correspondingly _off should IMO be a part of _disable callback().

Nop, mipi_dsi_dcs_set_display_on() should be part of prepare, to be called *before* the video stream starts, enable is called after in the atomic modeset chain,

Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 122

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+    if (ret < 0) {
+        dev_err(dev, "Failed on set display on: %d\n", ret);
+        return ret;
+    }
+    msleep(20);
Quoted 4 lines

Do we need to add here the following line?

dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

No, it will be changed by the DSI core.

Quoted 157 lines
Quoted 80 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +79 -0
+
+    return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+    ret = mipi_dsi_dcs_set_display_off(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to set display off: %d\n", ret);
+        return ret;
+    }
+    msleep(20);
+
+    ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(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)
+        return ret;
+
+    visionox_r66451_reset(ctx);
+
+    ret = visionox_r66451_on(ctx);
+    if (ret < 0) {
+        dev_err(dev, "Failed to initialize panel: %d\n", ret);
+        gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+        regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+        return ret;
+    }
+
+    ctx->prepared = true;
+    return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct device *dev = &ctx->dsi->dev;
+    int ret;
+
+    if (!ctx->prepared)
+        return 0;
+
+    ret = visionox_r66451_off(ctx);
+    if (ret < 0)
+        dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+    ctx->prepared = false;
+    return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+    .clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,

drivers/gpu/drm/panel/panel-visionox-r66451.c line 211

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+    .hdisplay = 1080,
+    .hsync_start = 1080 + 95,
+    .hsync_end = 1080 + 95 + 1,
+    .htotal = 1080 + 95 + 1 + 40,
+    .vdisplay = 2340,
+    .vsync_start = 2340 + 25,
+    .vsync_end = 2340 + 25 + 1,
+    .vtotal = 2340 + 25 + 1 + 4,
+    .width_mm = 0,
+    .height_mm = 0,

Please provide real values here.

Quoted 39 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +39 -0
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct drm_dsc_picture_parameter_set pps;
+    int ret;
+
+    if (ctx->enabled)
+        return 0;
+
+    if (!dsi->dsc) {
+        dev_err(&dsi->dev, "DSC not attached to DSI\n");
+        return -ENODEV;
+    }
+
+    drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+    ret = mipi_dsi_picture_parameter_set(dsi, &pps);
+
+    ctx->enabled = true;
+
+    return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+    ctx->enabled = false;
+
+    return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+                    struct drm_connector *connector)
+{
+    struct drm_display_mode *mode;
+

drivers/gpu/drm/panel/panel-visionox-r66451.c line 260

Quoted 10 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +10 -0
+    mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+    if (!mode)
+        return -ENOMEM;
+
+    drm_mode_set_name(mode);
+
+    mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+    connector->display_info.width_mm = mode->width_mm;
+    connector->display_info.height_mm = mode->height_mm;
+    drm_mode_probed_add(connector, mode);

Can we use drm_connector_helper_get_modes_fixed() instead?

Quoted 12 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +12 -0
+
+    return 1;
+}
+
+static const struct drm_panel_funcs visionox_r66451_funcs = {
+    .prepare = visionox_r66451_prepare,
+    .unprepare = visionox_r66451_unprepare,
+    .get_modes = visionox_r66451_get_modes,
+    .enable = visionox_r66451_enable,
+    .disable = visionox_r66451_disable,
+};
+
Quoted 8 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 278

Quoted 6 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +6 -0
+static int visionox_r66451_bl_update_status(struct backlight_device *bl)
+{
+    struct mipi_dsi_device *dsi = bl_get_data(bl);
+    u16 brightness = backlight_get_brightness(bl);
+
+    return mipi_dsi_dcs_set_display_brightness(dsi, cpu_to_le16(brightness));

mipi_dsi_dcs_set_display_brightness() already converts the brightness, so you don't need cpu_to_le16 here.

The _large variant must be used instead.

Neil

Quoted 120 lines
Quoted 119 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +117 -0
+}
+
+static const struct backlight_ops visionox_r66451_bl_ops = {
+    .update_status = visionox_r66451_bl_update_status,
+};
+
+static struct backlight_device *
+visionox_r66451_create_backlight(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    const struct backlight_properties props = {
+        .type = BACKLIGHT_RAW,
+        .brightness = 255,
+        .max_brightness = 4095,
+    };
+
+    return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+                          &visionox_r66451_bl_ops, &props);
+}
+
+static int visionox_r66451_probe(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    struct visionox_r66451 *ctx;
+    struct drm_dsc_config *dsc;
+    int ret = 0;
+
+    ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+    if (!ctx)
+        return -ENOMEM;
+
+    dsc = devm_kzalloc(dev, sizeof(*dsc), GFP_KERNEL);
+    if (!dsc)
+        return -ENOMEM;
+
+    /* Set DSC params */
+    dsc->dsc_version_major = 0x1;
+    dsc->dsc_version_minor = 0x2;
+
+    dsc->slice_height = 20;
+    dsc->slice_width = 540;
+    dsc->slice_count = 2;
+    dsc->bits_per_component = 8;
+    dsc->bits_per_pixel = 0x8 << 4;
+    dsc->block_pred_enable = true;
+
+    dsi->dsc = dsc;
+
+    ctx->supplies[0].supply = "vddio";
+    ctx->supplies[1].supply = "vdd";
+
+    ret = devm_regulator_bulk_get(&dsi->dev, ARRAY_SIZE(ctx->supplies),
+            ctx->supplies);
+
+    if (ret < 0)
+        return ret;
+
+    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");
+
+    ctx->dsi = dsi;
+    mipi_dsi_set_drvdata(dsi, ctx);
+
+    dsi->lanes = 4;
+    dsi->format = MIPI_DSI_FMT_RGB888;
+    dsi->mode_flags = MIPI_DSI_MODE_LPM | MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+    drm_panel_init(&ctx->panel, dev, &visionox_r66451_funcs, DRM_MODE_CONNECTOR_DSI);
+    ctx->panel.backlight = visionox_r66451_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;
+}
+
+static void visionox_r66451_remove(struct mipi_dsi_device *dsi)
+{
+    struct visionox_r66451 *ctx = mipi_dsi_get_drvdata(dsi);
+    int ret;
+
+    ret = mipi_dsi_detach(dsi);
+    if (ret < 0)
+        dev_err(&dsi->dev, "Failed to detach DSI host: %d\n", ret);
+
+    drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id visionox_r66451_of_match[] = {
+    {.compatible = "visionox,r66451"},
+    { /*sentinel*/ }
+};
+MODULE_DEVICE_TABLE(of, visionox_r66451_of_match);
+
+static struct mipi_dsi_driver visionox_r66451_driver = {
+    .probe = visionox_r66451_probe,
+    .remove = visionox_r66451_remove,
+    .driver = {
+        .name = "panel-visionox-r66451",
+        .of_match_table = visionox_r66451_of_match,
+    },
+};
+
+module_mipi_dsi_driver(visionox_r66451_driver);
+
+MODULE_AUTHOR("Jessica Zhang <[email protected]>");
+MODULE_DESCRIPTION("Panel driver for the Visionox R66451 AMOLED DSI panel");
+MODULE_LICENSE("GPL");
#23 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

Quoted 14 lines · Neil Armstrong
Quoted 13 lines · Dmitry Baryshkov
Quoted 12 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
  drivers/gpu/drm/panel/Kconfig                 |   8 + drivers/gpu/drm/panel/Makefile                |   1 + drivers/gpu/drm/panel/panel-visionox-r66451.c | 395
++++++++++++++++++++++++++

  3 files changed, 404 insertions(+)

[skipped]

Quoted 12 lines
Quoted 11 lines

drivers/gpu/drm/panel/panel-visionox-r66451.c line 117

Quoted 9 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -0
+
+    ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    ret = mipi_dsi_dcs_set_display_on(dsi);

Should the mipi_dsi_dcs_set_display_on() (and maybe exit sleep mode) be a a part of _enable()? Correspondingly _off should IMO be a part of _disable callback().

Quoted 1 line

Nop, mipi_dsi_dcs_set_display_on() should be part of prepare, to be called *before* the video stream starts, enable is called after in the atomic modeset chain,

To summarize our discussion: some controllers do not support sending commands in non-LPM mode. Thus the panel driver should send all commands before the DSI host switches from LPM to VIDEO mode.

Is this corret?

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines

+    if (ret < 0) {
+        dev_err(dev, "Failed on set display on: %d\n", ret); +        return ret;
+    }
+    msleep(20);

Quoted 6 lines
Quoted 4 lines

Do we need to add here the following line?

dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

No, it will be changed by the DSI core.

Hmm, where?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +3 -0
+
+    return 0;
+}

[skipped]

Quoted 12 lines
Quoted 10 lines
Quoted 8 lines

+static int visionox_r66451_bl_update_status(struct backlight_device *bl)

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +5 -0
+{
+    struct mipi_dsi_device *dsi = bl_get_data(bl);
+    u16 brightness = backlight_get_brightness(bl);
+
+    return mipi_dsi_dcs_set_display_brightness(dsi, 

cpu_to_le16(brightness));

mipi_dsi_dcs_set_display_brightness() already converts the brightness, so you don't need cpu_to_le16 here.

Quoted 1 line

The _large variant must be used instead.

But cpu_to_le16 is NOP, isn't it?

Signature · 2 lines
With best wishes
Dmitry
maintainer
#24 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

In reply to Jessica Zhang
Quoted 17 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
  drivers/gpu/drm/panel/Kconfig                 |   8 +
  drivers/gpu/drm/panel/Makefile                |   1 +
  drivers/gpu/drm/panel/panel-visionox-r66451.c | 395 ++++++++++++++++++++++++++
  3 files changed, 404 insertions(+)
drivers/gpu/drm/panel/Kconfig +0 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644

drivers/gpu/drm/panel/Kconfig config DRM_PANEL_VISIONOX_VTDR6130 · line 772

Quoted 7 lines
drivers/gpu/drm/panel/Kconfig +4 -0
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130
  	  Say Y here if you want to enable support for Visionox
  	  VTDR6130 1080x2400 AMOLED DSI panel.
 
+config DRM_PANEL_VISIONOX_R66451
+	tristate "Visionox R66451"
+	depends on OF
+	depends on DRM_MIPI_DSI

You may also want
+ depends on BACKLIGHT_CLASS_DEVICE

Quoted 420 lines
drivers/gpu/drm/panel/Kconfig +4 -0
+	help
+	  Say Y here if you want to enable support for Visionox
+	  R66451 1080x2340 AMOLED DSI panel.
+
  config DRM_PANEL_WIDECHIPS_WS2401
  	tristate "Widechips WS2401 DPI panel driver"
  	depends on SPI && GPIOLIB
drivers/gpu/drm/panel/Makefile +1 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += panel-tpo-tpg110.o
  obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o
  obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o
  obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o
+obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o
  obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o
  obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o
drivers/gpu/drm/panel/panel-visionox-r66451.c new file +395 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+	struct drm_panel panel;
+	struct mipi_dsi_device *dsi;
+	struct gpio_desc *reset_gpio;
+	struct regulator_bulk_data supplies[2];
+	bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct drm_panel *panel)
+{
+	return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+	gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+	usleep_range(10000, 10100);
+	gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+	usleep_range(10000, 10100);
+	gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+	usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	struct device *dev = &dsi->dev;
+	int ret;
+
+	dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xc2,
+			       0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
+			       0x09, 0x3c);
+	mipi_dsi_dcs_write_seq(dsi, 0xd7,
+			       0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+			       0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+			       0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+	mipi_dsi_dcs_write_seq(dsi, 0xde,
+			       0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+			       0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02, 0x00, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+	mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+	mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xc4,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32);
+	mipi_dsi_dcs_write_seq(dsi, 0xcf,
+			       0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
+			       0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+			       0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+	mipi_dsi_dcs_write_seq(dsi, 0xd3,
+			       0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07,
+			       0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0,
+			       0x3c, 0x9c);
+	mipi_dsi_dcs_write_seq(dsi, 0xd7,
+			       0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+			       0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+			       0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+	mipi_dsi_dcs_write_seq(dsi, 0xd8,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a,
+			       0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
+			       0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+	mipi_dsi_dcs_write_seq(dsi, 0xdf,
+			       0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00,
+			       0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+	mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00, 0x39, 0x04, 0x09, 0x34);
+	mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+	mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+	mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00);
+	mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+	mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01);
+	mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+	mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+	mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+	mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
+	mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x04, 0x37);
+	mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00, 0x09, 0x23);
+
+	ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+		return ret;
+	}
+	msleep(120);
+
+	ret = mipi_dsi_dcs_set_display_on(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed on set display on: %d\n", ret);
+		return ret;
+	}
+	msleep(20);
+
+	return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	struct device *dev = &dsi->dev;
+	int ret;
+
+	dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+	ret = mipi_dsi_dcs_set_display_off(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed to set display off: %d\n", ret);
+		return ret;
+	}
+	msleep(20);
+
+	ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+	if (ret < 0) {
+		dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+		return ret;
+	}
+	msleep(120);
+
+	return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(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)
+		return ret;
+
+	visionox_r66451_reset(ctx);
+
+	ret = visionox_r66451_on(ctx);
+	if (ret < 0) {
+		dev_err(dev, "Failed to initialize panel: %d\n", ret);
+		gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+		regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+		return ret;
+	}
+
+	ctx->prepared = true;
+	return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+	struct device *dev = &ctx->dsi->dev;
+	int ret;
+
+	if (!ctx->prepared)
+		return 0;
+
+	ret = visionox_r66451_off(ctx);
+	if (ret < 0)
+		dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+	gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+	regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+	ctx->prepared = false;
+	return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+	.clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,
+	.hdisplay = 1080,
+	.hsync_start = 1080 + 95,
+	.hsync_end = 1080 + 95 + 1,
+	.htotal = 1080 + 95 + 1 + 40,
+	.vdisplay = 2340,
+	.vsync_start = 2340 + 25,
+	.vsync_end = 2340 + 25 + 1,
+	.vtotal = 2340 + 25 + 1 + 4,
+	.width_mm = 0,
+	.height_mm = 0,
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	struct drm_dsc_picture_parameter_set pps;
+	int ret;
+
+	if (ctx->enabled)
+		return 0;
+
+	if (!dsi->dsc) {
+		dev_err(&dsi->dev, "DSC not attached to DSI\n");
+		return -ENODEV;
+	}
+
+	drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+	ret = mipi_dsi_picture_parameter_set(dsi, &pps);
+
+	ctx->enabled = true;
+
+	return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+	struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+	ctx->enabled = false;
+
+	return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+				    struct drm_connector *connector)
+{
+	struct drm_display_mode *mode;
+
+	mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+	if (!mode)
+		return -ENOMEM;
+
+	drm_mode_set_name(mode);
+
+	mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+	connector->display_info.width_mm = mode->width_mm;
+	connector->display_info.height_mm = mode->height_mm;
+	drm_mode_probed_add(connector, mode);
+
+	return 1;
+}
+
+static const struct drm_panel_funcs visionox_r66451_funcs = {
+	.prepare = visionox_r66451_prepare,
+	.unprepare = visionox_r66451_unprepare,
+	.get_modes = visionox_r66451_get_modes,
+	.enable = visionox_r66451_enable,
+	.disable = visionox_r66451_disable,
+};
+
+static int visionox_r66451_bl_update_status(struct backlight_device *bl)
+{
+	struct mipi_dsi_device *dsi = bl_get_data(bl);
+	u16 brightness = backlight_get_brightness(bl);
+
+	return mipi_dsi_dcs_set_display_brightness(dsi, cpu_to_le16(brightness));
+}
+
+static const struct backlight_ops visionox_r66451_bl_ops = {
+	.update_status = visionox_r66451_bl_update_status,
+};
+
+static struct backlight_device *
+visionox_r66451_create_backlight(struct mipi_dsi_device *dsi)
+{
+	struct device *dev = &dsi->dev;
+	const struct backlight_properties props = {
+		.type = BACKLIGHT_RAW,
+		.brightness = 255,
+		.max_brightness = 4095,
+	};
+
+	return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+					      &visionox_r66451_bl_ops, &props);
+}
+
+static int visionox_r66451_probe(struct mipi_dsi_device *dsi)
+{
+	struct device *dev = &dsi->dev;
+	struct visionox_r66451 *ctx;
+	struct drm_dsc_config *dsc;
+	int ret = 0;
+
+	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return -ENOMEM;
+
+	dsc = devm_kzalloc(dev, sizeof(*dsc), GFP_KERNEL);
+	if (!dsc)
+		return -ENOMEM;
+
+	/* Set DSC params */
+	dsc->dsc_version_major = 0x1;
+	dsc->dsc_version_minor = 0x2;
+
+	dsc->slice_height = 20;
+	dsc->slice_width = 540;
+	dsc->slice_count = 2;
+	dsc->bits_per_component = 8;
+	dsc->bits_per_pixel = 0x8 << 4;
+	dsc->block_pred_enable = true;
+
+	dsi->dsc = dsc;
+
+	ctx->supplies[0].supply = "vddio";
+	ctx->supplies[1].supply = "vdd";
+
+	ret = devm_regulator_bulk_get(&dsi->dev, ARRAY_SIZE(ctx->supplies),
+			ctx->supplies);
+
+	if (ret < 0)
+		return ret;
+
+	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");
+
+	ctx->dsi = dsi;
+	mipi_dsi_set_drvdata(dsi, ctx);
+
+	dsi->lanes = 4;
+	dsi->format = MIPI_DSI_FMT_RGB888;
+	dsi->mode_flags = MIPI_DSI_MODE_LPM | MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+	drm_panel_init(&ctx->panel, dev, &visionox_r66451_funcs, DRM_MODE_CONNECTOR_DSI);
+	ctx->panel.backlight = visionox_r66451_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;
+}
+
+static void visionox_r66451_remove(struct mipi_dsi_device *dsi)
+{
+	struct visionox_r66451 *ctx = mipi_dsi_get_drvdata(dsi);
+	int ret;
+
+	ret = mipi_dsi_detach(dsi);
+	if (ret < 0)
+		dev_err(&dsi->dev, "Failed to detach DSI host: %d\n", ret);
+
+	drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id visionox_r66451_of_match[] = {
+	{.compatible = "visionox,r66451"},
+	{ /*sentinel*/ }
+};
+MODULE_DEVICE_TABLE(of, visionox_r66451_of_match);
+
+static struct mipi_dsi_driver visionox_r66451_driver = {
+	.probe = visionox_r66451_probe,
+	.remove = visionox_r66451_remove,
+	.driver = {
+		.name = "panel-visionox-r66451",
+		.of_match_table = visionox_r66451_of_match,
+	},
+};
+
+module_mipi_dsi_driver(visionox_r66451_driver);
+
+MODULE_AUTHOR("Jessica Zhang <[email protected]>");
+MODULE_DESCRIPTION("Panel driver for the Visionox R66451 AMOLED DSI panel");
+MODULE_LICENSE("GPL");
#25 lore raw

Re: [PATCH 2/2] drm/panel: Add driver for Visionox r66451 panel

Quoted 14 lines · Neil Armstrong
Quoted 13 lines · Jessica Zhang

Add support for the 1080x2340 Visionox R66451 AMOLED DSI panel that comes with the Qualcomm HDK8350 display expansion pack.

The panel enables display compression (DSC v1.2) by default.

---
  drivers/gpu/drm/panel/Kconfig                 |   8 + drivers/gpu/drm/panel/Makefile                |   1 + drivers/gpu/drm/panel/panel-visionox-r66451.c | 395
++++++++++++++++++++++++++

  3 files changed, 404 insertions(+)
Quoted 15 lines
Quoted 11 lines
drivers/gpu/drm/panel/Kconfig +0 -0
index 29cf5fa39ff2..9c2c36dbddf3 100644
@@ -766,6 +766,14 @@ config DRM_PANEL_VISIONOX_VTDR6130

        Say Y here if you want to enable support for Visionox VTDR6130 1080x2400 AMOLED DSI panel. +config DRM_PANEL_VISIONOX_R66451
+    tristate "Visionox R66451"
+    depends on OF
+    depends on DRM_MIPI_DSI

You may also want
+    depends on BACKLIGHT_CLASS_DEVICE

Hi Neil,

Acked.

Thanks,

Jessica Zhang

Quoted 434 lines
Quoted 433 lines

+    help
+      Say Y here if you want to enable support for Visionox +      R66451 1080x2340 AMOLED DSI panel.
+
  config DRM_PANEL_WIDECHIPS_WS2401
      tristate "Widechips WS2401 DPI panel driver" depends on SPI && GPIOLIB

drivers/gpu/drm/panel/Makefile +0 -0
index b3e8ba29edd3..e043a92ee676 100644
@@ -78,5 +78,6 @@ obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += 

panel-tpo-tpg110.o
  obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o obj-$(CONFIG_DRM_PANEL_VISIONOX_RM69299) += panel-visionox-rm69299.o obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o +obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +2 -0
new file mode 100644
index 000000000000..e3648ead3e84
@@ -0,0 +1,395 @@
+//SPDX-License-Identifier: GPL-2.0-only
+//Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights 

reserved.

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +25 -0
+
+#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 <drm/display/drm_dsc.h>
+#include <drm/display/drm_dsc_helper.h>
+
+#include <video/mipi_display.h>
+
+struct visionox_r66451 {
+    struct drm_panel panel;
+    struct mipi_dsi_device *dsi;
+    struct gpio_desc *reset_gpio;
+    struct regulator_bulk_data supplies[2];
+    bool prepared, enabled;
+};
+
+static inline struct visionox_r66451 *to_visionox_r66451(struct 

drm_panel *panel)

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +34 -0
+{
+    return container_of(panel, struct visionox_r66451, panel);
+}
+
+static void visionox_r66451_reset(struct visionox_r66451 *ctx)
+{
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    usleep_range(10000, 10100);
+    gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+    usleep_range(10000, 10100);
+}
+
+static int visionox_r66451_on(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc2,
+                   0x09, 0x24, 0x0c, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
+                   0x09, 0x3c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a,
+                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
+                   0x3c, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xde,
+                   0x40, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18,
+                   0x10, 0x00, 0x18, 0x00, 0x18, 0x00, 0x18, 0x02, 

0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xe8, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x00, 0x08);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xc4,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +                   0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32); +    mipi_dsi_dcs_write_seq(dsi, 0xcf,
+                   0x64, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, +                   0x00, 0x0b, 0x77, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +                   0x02, 0x02, 0x02, 0x02, 0x02, 0x03);
+    mipi_dsi_dcs_write_seq(dsi, 0xd3,
+                   0x45, 0x00, 0x00, 0x01, 0x13, 0x15, 0x00, 0x15, 0x07, +                   0x0f, 0x77, 0x77, 0x77, 0x37, 0xb2, 0x11, 0x00, 0xa0, +                   0x3c, 0x9c);
+    mipi_dsi_dcs_write_seq(dsi, 0xd7,
+                   0x00, 0xb9, 0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a, +                   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, +                   0x34, 0x00, 0x40, 0x04, 0x00, 0xa0, 0x0a); +    mipi_dsi_dcs_write_seq(dsi, 0xd8,
+                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +                   0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, 0x00, 0x3a, +                   0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +                   0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, +                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, +                   0x00, 0x32, 0x00, 0x0a, 0x00, 0x22);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf,
+                   0x50, 0x42, 0x58, 0x81, 0x2d, 0x00, 0x00, 0x00, 0x00, +                   0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +                   0x00, 0x00, 0x01, 0x0f, 0xff, 0xd4, 0x0e, 0x00, 0x00, +                   0x00, 0x00, 0x00, 0x00, 0x0f, 0x53, 0xf1, 0x00, 0x00, +                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xf7, 0x01);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x80);
+    mipi_dsi_dcs_write_seq(dsi, 0xe4, 0x34, 0xb4, 0x00, 0x00, 0x00, 0x39, 0x04, 0x09, 0x34);
+    mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x00);
+    mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x04);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x40);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x50, 0x00, 0x00, 0x00, 0x00); +    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x11);
+    mipi_dsi_dcs_write_seq(dsi, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x01); +    mipi_dsi_dcs_write_seq(dsi, 0xf4, 0x00, 0x02);
+    mipi_dsi_dcs_write_seq(dsi, 0xf2, 0x19);
+    mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x50, 0x42);
+    mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK); +    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x04, 0x37);
+    mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00, 0x09, 0x23);

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +64 -0
+
+    ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    ret = mipi_dsi_dcs_set_display_on(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed on set display on: %d\n", ret);
+        return ret;
+    }
+    msleep(20);
+
+    return 0;
+}
+
+static int visionox_r66451_off(struct visionox_r66451 *ctx)
+{
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct device *dev = &dsi->dev;
+    int ret;
+
+    dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+    ret = mipi_dsi_dcs_set_display_off(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to set display off: %d\n", ret);
+        return ret;
+    }
+    msleep(20);
+
+    ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+    if (ret < 0) {
+        dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+        return ret;
+    }
+    msleep(120);
+
+    return 0;
+}
+
+static int visionox_r66451_prepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(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)
+        return ret;
+
+    visionox_r66451_reset(ctx);
+
+    ret = visionox_r66451_on(ctx);
+    if (ret < 0) {
+        dev_err(dev, "Failed to initialize panel: %d\n", ret);
+        gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+        regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), 

ctx->supplies);
+        return ret;
+    }

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +104 -0
+
+    ctx->prepared = true;
+    return 0;
+}
+
+static int visionox_r66451_unprepare(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct device *dev = &ctx->dsi->dev;
+    int ret;
+
+    if (!ctx->prepared)
+        return 0;
+
+    ret = visionox_r66451_off(ctx);
+    if (ret < 0)
+        dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
+
+    gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+    regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+    ctx->prepared = false;
+    return 0;
+}
+
+static const struct drm_display_mode visionox_r66451_mode = {
+    .clock = (1080 + 95 + 1 + 40) * (2340 + 25 + 1 + 4) * 120 / 1000,
+    .hdisplay = 1080,
+    .hsync_start = 1080 + 95,
+    .hsync_end = 1080 + 95 + 1,
+    .htotal = 1080 + 95 + 1 + 40,
+    .vdisplay = 2340,
+    .vsync_start = 2340 + 25,
+    .vsync_end = 2340 + 25 + 1,
+    .vtotal = 2340 + 25 + 1 + 4,
+    .width_mm = 0,
+    .height_mm = 0,
+};
+
+static int visionox_r66451_enable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+    struct mipi_dsi_device *dsi = ctx->dsi;
+    struct drm_dsc_picture_parameter_set pps;
+    int ret;
+
+    if (ctx->enabled)
+        return 0;
+
+    if (!dsi->dsc) {
+        dev_err(&dsi->dev, "DSC not attached to DSI\n");
+        return -ENODEV;
+    }
+
+    drm_dsc_pps_payload_pack(&pps, dsi->dsc);
+    ret = mipi_dsi_picture_parameter_set(dsi, &pps);
+
+    ctx->enabled = true;
+
+    return 0;
+}
+
+static int visionox_r66451_disable(struct drm_panel *panel)
+{
+    struct visionox_r66451 *ctx = to_visionox_r66451(panel);
+
+    ctx->enabled = false;
+
+    return 0;
+}
+
+static int visionox_r66451_get_modes(struct drm_panel *panel,
+                    struct drm_connector *connector)
+{
+    struct drm_display_mode *mode;
+
+    mode = drm_mode_duplicate(connector->dev, &visionox_r66451_mode);
+    if (!mode)
+        return -ENOMEM;
+
+    drm_mode_set_name(mode);
+
+    mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+    connector->display_info.width_mm = mode->width_mm;
+    connector->display_info.height_mm = mode->height_mm;
+    drm_mode_probed_add(connector, mode);
+
+    return 1;
+}
+
+static const struct drm_panel_funcs visionox_r66451_funcs = {
+    .prepare = visionox_r66451_prepare,
+    .unprepare = visionox_r66451_unprepare,
+    .get_modes = visionox_r66451_get_modes,
+    .enable = visionox_r66451_enable,
+    .disable = visionox_r66451_disable,
+};
+
+static int visionox_r66451_bl_update_status(struct backlight_device *bl)
+{
+    struct mipi_dsi_device *dsi = bl_get_data(bl);
+    u16 brightness = backlight_get_brightness(bl);
+
+    return mipi_dsi_dcs_set_display_brightness(dsi, 

cpu_to_le16(brightness));

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +60 -0
+}
+
+static const struct backlight_ops visionox_r66451_bl_ops = {
+    .update_status = visionox_r66451_bl_update_status,
+};
+
+static struct backlight_device *
+visionox_r66451_create_backlight(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    const struct backlight_properties props = {
+        .type = BACKLIGHT_RAW,
+        .brightness = 255,
+        .max_brightness = 4095,
+    };
+
+    return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+                          &visionox_r66451_bl_ops, &props);
+}
+
+static int visionox_r66451_probe(struct mipi_dsi_device *dsi)
+{
+    struct device *dev = &dsi->dev;
+    struct visionox_r66451 *ctx;
+    struct drm_dsc_config *dsc;
+    int ret = 0;
+
+    ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+    if (!ctx)
+        return -ENOMEM;
+
+    dsc = devm_kzalloc(dev, sizeof(*dsc), GFP_KERNEL);
+    if (!dsc)
+        return -ENOMEM;
+
+    /* Set DSC params */
+    dsc->dsc_version_major = 0x1;
+    dsc->dsc_version_minor = 0x2;
+
+    dsc->slice_height = 20;
+    dsc->slice_width = 540;
+    dsc->slice_count = 2;
+    dsc->bits_per_component = 8;
+    dsc->bits_per_pixel = 0x8 << 4;
+    dsc->block_pred_enable = true;
+
+    dsi->dsc = dsc;
+
+    ctx->supplies[0].supply = "vddio";
+    ctx->supplies[1].supply = "vdd";
+
+    ret = devm_regulator_bulk_get(&dsi->dev, ARRAY_SIZE(ctx->supplies),
+            ctx->supplies);
+
+    if (ret < 0)
+        return ret;
+
+    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");

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +9 -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_LPM | MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+    drm_panel_init(&ctx->panel, dev, &visionox_r66451_funcs, 

DRM_MODE_CONNECTOR_DSI);
+    ctx->panel.backlight = visionox_r66451_create_backlight(dsi); +    if (IS_ERR(ctx->panel.backlight))
+        return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight), +                "Failed to create backlight\n");

drivers/gpu/drm/panel/panel-visionox-r66451.c new file +43 -0
+
+    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;
+}
+
+static void visionox_r66451_remove(struct mipi_dsi_device *dsi)
+{
+    struct visionox_r66451 *ctx = mipi_dsi_get_drvdata(dsi);
+    int ret;
+
+    ret = mipi_dsi_detach(dsi);
+    if (ret < 0)
+        dev_err(&dsi->dev, "Failed to detach DSI host: %d\n", ret);
+
+    drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id visionox_r66451_of_match[] = {
+    {.compatible = "visionox,r66451"},
+    { /*sentinel*/ }
+};
+MODULE_DEVICE_TABLE(of, visionox_r66451_of_match);
+
+static struct mipi_dsi_driver visionox_r66451_driver = {
+    .probe = visionox_r66451_probe,
+    .remove = visionox_r66451_remove,
+    .driver = {
+        .name = "panel-visionox-r66451",
+        .of_match_table = visionox_r66451_of_match,
+    },
+};
+
+module_mipi_dsi_driver(visionox_r66451_driver);
+
+MODULE_AUTHOR("Jessica Zhang <[email protected]>");
+MODULE_DESCRIPTION("Panel driver for the Visionox R66451 AMOLED DSI 

panel");
+MODULE_LICENSE("GPL");