Devicetree
 help / color / mirror / Atom feed
* [PATCH v1 0/2] Add support for Sitronix ST75256 LCD panels
@ 2026-12-06 13:13 Cyril Hrubis
  2026-12-06 13:13 ` [PATCH v1 1/2] dt-bindings: display: sitronix,st75256: Add DT schema Cyril Hrubis
  2026-12-06 13:13 ` [PATCH v1 2/2] drm/sitronix: Add driver for Sitronix ST75256 LCD panels Cyril Hrubis
  0 siblings, 2 replies; 5+ messages in thread
From: Cyril Hrubis @ 2026-12-06 13:13 UTC (permalink / raw)
  To: dri-devel, devicetree
  Cc: lars.rask, Cyril Hrubis, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Javier Martinez Canillas,
	Marcus Folkesson, Iker Pedrosa, linux-kernel

From: Cyril Hrubis <metan@ucw.cz>

Adds driver and bindings for Sitronix ST75256 LCD panels over SPI.

Cyril Hrubis (2):
  dt-bindings: display: sitronix,st75256: Add DT schema
  drm/sitronix: Add driver for Sitronix ST75256 LCD panels

 .../bindings/display/sitronix,st75256.yaml    | 113 +++
 MAINTAINERS                                   |   7 +
 drivers/gpu/drm/sitronix/Kconfig              |  15 +
 drivers/gpu/drm/sitronix/Makefile             |   1 +
 drivers/gpu/drm/sitronix/st75256.c            | 879 ++++++++++++++++++
 5 files changed, 1015 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/sitronix,st75256.yaml
 create mode 100644 drivers/gpu/drm/sitronix/st75256.c

-- 
2.51.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v1 1/2] dt-bindings: display: sitronix,st75256: Add DT schema
  2026-12-06 13:13 [PATCH v1 0/2] Add support for Sitronix ST75256 LCD panels Cyril Hrubis
@ 2026-12-06 13:13 ` Cyril Hrubis
  2026-12-06 13:29   ` sashiko-bot
  2026-12-06 13:13 ` [PATCH v1 2/2] drm/sitronix: Add driver for Sitronix ST75256 LCD panels Cyril Hrubis
  1 sibling, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2026-12-06 13:13 UTC (permalink / raw)
  To: dri-devel, devicetree
  Cc: lars.rask, Cyril Hrubis, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Javier Martinez Canillas,
	Marcus Folkesson, Iker Pedrosa, linux-kernel

From: Cyril Hrubis <metan@ucw.cz>

Add a binding for the Sitronix ST75256, a controller for monochrome and
4-level grayscale dot matrix LCD panels with up to 256 segment and 162
common lines, connected over 4-line SPI with a separate data/command
line.

The panel is described the same way as for the Sitronix ST75156 and
ST7571 controllers, the resolution with panel-timing and the physical
size with width-mm and height-mm. The LCD operating voltage (contrast)
is panel specific and required, the gray levels for the grayscale mode
are optional.

Signed-off-by: Cyril Hrubis <metan@ucw.cz>
---
 .../bindings/display/sitronix,st75256.yaml    | 113 ++++++++++++++++++
 1 file changed, 113 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/sitronix,st75256.yaml

diff --git a/Documentation/devicetree/bindings/display/sitronix,st75256.yaml b/Documentation/devicetree/bindings/display/sitronix,st75256.yaml
new file mode 100644
index 000000000000..a4486507f774
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/sitronix,st75256.yaml
@@ -0,0 +1,113 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/sitronix,st75256.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sitronix ST75256 Display Controller
+
+maintainers:
+  - Cyril Hrubis <metan@ucw.cz>
+
+description:
+  Sitronix ST75256 is a driver and controller for 4-level grayscale and
+  monochrome dot matrix LCD panels with up to 256 segment and 162 common
+  lines. The panel is connected over a 4-line SPI interface with a separate
+  data/command line. The panel is described in portrait orientation, i.e.
+  the width is along the common lines and the height along the segment lines.
+
+allOf:
+  - $ref: panel/panel-common.yaml#
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+properties:
+  compatible:
+    const: sitronix,st75256
+
+  reg:
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 12500000
+
+  reset-gpios:
+    maxItems: 1
+
+  dc-gpios:
+    maxItems: 1
+    description: Data/command selection (A0) line.
+
+  backlight: true
+  width-mm: true
+  height-mm: true
+
+  panel-timing:
+    description:
+      Only hactive and vactive are used and describe the panel resolution.
+      The hactive has to be a multiple of 8 up to 160, the vactive up to
+      256. The remaining timings are not applicable and should be zero.
+
+  sitronix,vop:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 0x55
+    maximum: 0x168
+    description:
+      LCD operating voltage (contrast) setting, V0 = 3.6V + vop * 0.04V. The
+      optimal value depends on the panel. It is added to the panel specific
+      offset programmed into the controller OTP by the panel manufacturer.
+
+  sitronix,gray-levels:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    items:
+      - description: Light gray level
+        maximum: 0x1f
+      - description: Dark gray level
+        maximum: 0x1f
+    description:
+      Gray levels used in the 4-level grayscale mode. If not present, values
+      calibrated for the JLX256128 and JLX256160 panels are used.
+
+required:
+  - compatible
+  - reg
+  - reset-gpios
+  - dc-gpios
+  - width-mm
+  - height-mm
+  - panel-timing
+  - sitronix,vop
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        display@0 {
+            compatible = "sitronix,st75256";
+            reg = <0>;
+            spi-max-frequency = <12500000>;
+            reset-gpios = <&gpio 17 GPIO_ACTIVE_LOW>;
+            dc-gpios = <&gpio 25 GPIO_ACTIVE_HIGH>;
+            backlight = <&backlight>;
+            width-mm = <40>;
+            height-mm = <64>;
+            sitronix,vop = <284>;
+
+            panel-timing {
+                hactive = <160>;
+                vactive = <256>;
+                hback-porch = <0>;
+                hfront-porch = <0>;
+                hsync-len = <0>;
+                vback-porch = <0>;
+                vfront-porch = <0>;
+                vsync-len = <0>;
+                clock-frequency = <0>;
+            };
+        };
+    };
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 2/2] drm/sitronix: Add driver for Sitronix ST75256 LCD panels
  2026-12-06 13:13 [PATCH v1 0/2] Add support for Sitronix ST75256 LCD panels Cyril Hrubis
  2026-12-06 13:13 ` [PATCH v1 1/2] dt-bindings: display: sitronix,st75256: Add DT schema Cyril Hrubis
@ 2026-12-06 13:13 ` Cyril Hrubis
  2026-12-06 13:35   ` sashiko-bot
  1 sibling, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2026-12-06 13:13 UTC (permalink / raw)
  To: dri-devel, devicetree
  Cc: lars.rask, Cyril Hrubis, David Airlie, Simona Vetter,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Javier Martinez Canillas,
	Marcus Folkesson, Iker Pedrosa, linux-kernel

From: Cyril Hrubis <metan@ucw.cz>

Add a DRM driver for Sitronix ST75256 based monochrome and 4-level
grayscale LCD panels connected over 4-wire SPI, such as the JLX256128
and JLX256160 modules.

The controller is programmed to scan the display RAM page direction
first, which makes each panel column a row of pixels in memory, so the
panel is exposed in portrait orientation. In this layout the R1 and R2
formats match the display RAM layout of the monochrome and grayscale
mode and are transferred without conversion. XRGB8888 is supported as
well and converted to 4-level gray. The controller display mode is
switched based on the framebuffer format.

Only the damaged area, rounded to whole bytes, is transferred on
updates, which is about 0.4 ms for small updates compared to about 3.5
ms (R1) and 7 ms (R2) for a full 160x256 frame at the 12.5 MHz maximal
SPI clock.

The initialization sequence follows the datasheet reference sequence,
the factory Vop offset is loaded from the OTP. The Vop (contrast) and
optionally the gray levels are read from the device tree since they are
panel specific.

Tested on Raspberry Pi Zero W with JLX256128 and JLX256160 panels.

Signed-off-by: Cyril Hrubis <metan@ucw.cz>
---
 MAINTAINERS                        |   7 +
 drivers/gpu/drm/sitronix/Kconfig   |  15 +
 drivers/gpu/drm/sitronix/Makefile  |   1 +
 drivers/gpu/drm/sitronix/st75256.c | 879 +++++++++++++++++++++++++++++
 4 files changed, 902 insertions(+)
 create mode 100644 drivers/gpu/drm/sitronix/st75256.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 84cb98ef4c49..f99f43beb121 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8726,6 +8726,13 @@ T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
 F:	Documentation/devicetree/bindings/display/sitronix,st7586.yaml
 F:	drivers/gpu/drm/sitronix/st7586.c
 
+DRM DRIVER FOR SITRONIX ST75256 PANELS
+M:	Cyril Hrubis <metan@ucw.cz>
+S:	Maintained
+T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
+F:	Documentation/devicetree/bindings/display/sitronix,st75256.yaml
+F:	drivers/gpu/drm/sitronix/st75256.c
+
 DRM DRIVER FOR SITRONIX ST7571 PANELS
 M:	Marcus Folkesson <marcus.folkesson@gmail.com>
 S:	Maintained
diff --git a/drivers/gpu/drm/sitronix/Kconfig b/drivers/gpu/drm/sitronix/Kconfig
index 41a428ef8295..907ee32cc9b2 100644
--- a/drivers/gpu/drm/sitronix/Kconfig
+++ b/drivers/gpu/drm/sitronix/Kconfig
@@ -39,6 +39,21 @@ config DRM_ST7571_SPI
 
 	  if M is selected the module will be called st7571-spi.
 
+config DRM_ST75256
+	tristate "DRM support for Sitronix ST75256 display panels"
+	depends on DRM && SPI && MMU
+	select BACKLIGHT_CLASS_DEVICE
+	select DRM_CLIENT_SELECTION
+	select DRM_GEM_SHMEM_HELPER
+	select DRM_KMS_HELPER
+	select VIDEOMODE_HELPERS
+	help
+	  DRM driver for Sitronix ST75256 based monochrome and 4-level
+	  grayscale LCD panels connected over 4-wire SPI, e.g. JLX256128
+	  and JLX256160.
+
+	  If M is selected the module will be called st75256.
+
 config DRM_ST7586
 	tristate "DRM support for Sitronix ST7586 display panels"
 	depends on DRM && SPI
diff --git a/drivers/gpu/drm/sitronix/Makefile b/drivers/gpu/drm/sitronix/Makefile
index d03beff37628..7eba92a5b1fe 100644
--- a/drivers/gpu/drm/sitronix/Makefile
+++ b/drivers/gpu/drm/sitronix/Makefile
@@ -1,6 +1,7 @@
 obj-$(CONFIG_DRM_ST7571)		+= st7571.o
 obj-$(CONFIG_DRM_ST7571_I2C)		+= st7571-i2c.o
 obj-$(CONFIG_DRM_ST7571_SPI)		+= st7571-spi.o
+obj-$(CONFIG_DRM_ST75256)		+= st75256.o
 obj-$(CONFIG_DRM_ST7586)		+= st7586.o
 obj-$(CONFIG_DRM_ST7735R)		+= st7735r.o
 obj-$(CONFIG_DRM_ST7920)		+= st7920.o
diff --git a/drivers/gpu/drm/sitronix/st75256.c b/drivers/gpu/drm/sitronix/st75256.c
new file mode 100644
index 000000000000..4a931208cec5
--- /dev/null
+++ b/drivers/gpu/drm/sitronix/st75256.c
@@ -0,0 +1,879 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * DRM driver for Sitronix ST75256 based monochrome and 4-level grayscale
+ * LCD panels connected over 4-wire SPI.
+ *
+ * The controller is programmed to scan the display RAM page direction first,
+ * which makes each column of the panel a row of pixels in memory. The panel
+ * is therefore exposed in portrait orientation, i.e. the 256 pixel long side
+ * of the panel is vertical. In this layout the DRM_FORMAT_R1 and
+ * DRM_FORMAT_R2 formats (first pixel in the most significant bits) match the
+ * display RAM layout in monochrome and grayscale mode respectively and are
+ * sent to the controller as they are.
+ *
+ * Copyright (C) 2026 Cyril Hrubis <metan@ucw.cz>
+ */
+
+#include <linux/backlight.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/iosys-map.h>
+#include <linux/module.h>
+#include <linux/property.h>
+#include <linux/spi/spi.h>
+
+#include <video/display_timing.h>
+#include <video/of_display_timing.h>
+
+#include <drm/clients/drm_client_setup.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_damage_helper.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_fbdev_shmem.h>
+#include <drm/drm_format_helper.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_framebuffer.h>
+#include <drm/drm_gem_atomic_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_gem_shmem_helper.h>
+#include <drm/drm_modeset_helper_vtables.h>
+#include <drm/drm_print.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_rect.h>
+
+#define DRIVER_NAME	"st75256"
+#define DRIVER_DESC	"DRM driver for Sitronix ST75256 LCD panels"
+#define DRIVER_MAJOR	1
+#define DRIVER_MINOR	0
+
+/* Command set selection */
+#define ST75256_EXT1			0x30
+#define ST75256_EXT2			0x31
+
+/* Extension 1 commands */
+#define ST75256_SET_COL_ADDR		0x15
+#define ST75256_PWR_CTRL		0x20
+#define ST75256_WRITE_DATA		0x5c
+#define ST75256_SET_PAGE_ADDR		0x75
+#define ST75256_SET_VOP			0x81
+#define ST75256_SLEEP_OUT		0x94
+#define ST75256_SLEEP_IN		0x95
+#define ST75256_DISP_INVERSE		0xa7
+#define ST75256_DISP_OFF		0xae
+#define ST75256_DISP_ON			0xaf
+#define ST75256_SET_SCAN_DIR		0xbc
+#define ST75256_DISP_CTRL		0xca
+#define ST75256_DISP_MODE		0xf0
+
+/* Extension 2 commands */
+#define ST75256_SET_GRAY_LEVEL		0x20
+#define ST75256_ANALOG_CIRCUIT		0x32
+#define ST75256_BOOSTER_LEVEL		0x51
+#define ST75256_OTP_AUTO_READ_CTRL	0xd7
+#define ST75256_OTP_WR_RD_CTRL		0xe0
+#define ST75256_OTP_CTRL_OUT		0xe1
+#define ST75256_OTP_READ		0xe3
+#define ST75256_FRAME_RATE		0xf0
+
+/* ST75256_PWR_CTRL bits */
+#define ST75256_PWR_VR			BIT(0)
+#define ST75256_PWR_VF			BIT(1)
+#define ST75256_PWR_VB			BIT(3)
+
+/* ST75256_SET_SCAN_DIR bits */
+#define ST75256_SCAN_MX			BIT(1)
+#define ST75256_SCAN_PAGE_FIRST		BIT(2)
+
+/* ST75256_ANALOG_CIRCUIT parameters */
+#define ST75256_BOOSTER_EFF_LEVEL1	0x01
+#define ST75256_BIAS_1_12		0x02
+
+/* ST75256_BOOSTER_LEVEL values */
+#define ST75256_BOOSTER_X10		0xfb
+
+/* ST75256_DISP_MODE values */
+#define ST75256_MODE_MONO		0x10
+#define ST75256_MODE_GRAY		0x11
+
+/* ST75256_SET_VOP range, V0 = 3.6V + Vop * 0.04V, i.e. 7.0V to 18.0V */
+#define ST75256_VOP_MIN			0x55
+#define ST75256_VOP_MAX			0x168
+
+/* ST75256_SET_GRAY_LEVEL light and dark gray level maximum */
+#define ST75256_GRAY_LEVEL_MAX		0x1f
+
+/*
+ * Default gray levels, calibrated on JLX256128 and JLX256160 panels. They
+ * differ from the controller defaults since the display is inverted
+ * (ST75256_DISP_INVERSE).
+ */
+#define ST75256_GRAY_LIGHT_DEFAULT	0x14
+#define ST75256_GRAY_DARK_DEFAULT	0x0f
+
+/*
+ * Maximal panel size in the portrait orientation, 160 of the 162 COM lines
+ * (whole bytes in monochrome mode) and 256 SEG lines.
+ */
+#define ST75256_MAX_WIDTH		160
+#define ST75256_MAX_HEIGHT		256
+
+#define ST75256_CMD_BUF_LEN		16
+
+struct st75256_panel {
+	/* Pixels along the page (COM) direction, multiple of 8 */
+	unsigned int width;
+	/* Pixels along the column (SEG) direction */
+	unsigned int height;
+	unsigned int width_mm;
+	unsigned int height_mm;
+	/* LCD operating voltage (contrast) */
+	u16 vop;
+	/* Gray levels for 4-level grayscale mode */
+	u8 gray_light;
+	u8 gray_dark;
+};
+
+struct st75256_device {
+	struct drm_device drm;
+	struct drm_plane plane;
+	struct drm_crtc crtc;
+	struct drm_encoder encoder;
+	struct drm_connector connector;
+	struct drm_display_mode mode;
+
+	struct spi_device *spi;
+	struct gpio_desc *reset;
+	struct gpio_desc *dc;
+	struct backlight_device *backlight;
+	/* Panel parameters from the device tree */
+	struct st75256_panel panel;
+
+	/* Currently programmed ST75256_MODE_*, 0 when unknown */
+	u8 hw_mode;
+
+	/* DMA safe buffers */
+	u8 *cmd_buf;
+	u8 *tx_buf;
+
+	/* One line of 8-bit gray pixels for the XRGB8888 conversion */
+	u8 *line_buf;
+};
+
+static inline struct st75256_device *drm_to_st75256(struct drm_device *drm)
+{
+	return container_of(drm, struct st75256_device, drm);
+}
+
+static int st75256_spi_write(struct st75256_device *st75256, bool data,
+			     const u8 *buf, size_t len)
+{
+	size_t max_len = spi_max_transfer_size(st75256->spi);
+	int ret;
+
+	gpiod_set_value_cansleep(st75256->dc, data);
+
+	while (len) {
+		size_t chunk = min(len, max_len);
+
+		ret = spi_write(st75256->spi, buf, chunk);
+		if (ret)
+			return ret;
+
+		buf += chunk;
+		len -= chunk;
+	}
+
+	return 0;
+}
+
+static int st75256_cmd_buf(struct st75256_device *st75256, u8 cmd,
+			   const u8 *params, size_t num)
+{
+	int ret;
+
+	if (WARN_ON(num > ST75256_CMD_BUF_LEN))
+		return -EINVAL;
+
+	st75256->cmd_buf[0] = cmd;
+	ret = st75256_spi_write(st75256, false, st75256->cmd_buf, 1);
+	if (ret || !num)
+		return ret;
+
+	memcpy(st75256->cmd_buf, params, num);
+
+	return st75256_spi_write(st75256, true, st75256->cmd_buf, num);
+}
+
+/*
+ * Sends a command followed by optional parameters. Does nothing if a previous
+ * command failed, so that a sequence can be checked for errors once at the end.
+ */
+#define st75256_cmd(st75256, err, cmd, seq...)				\
+	do {								\
+		const u8 d[] = { seq };					\
+		int *e = (err);						\
+									\
+		if (!*e)						\
+			*e = st75256_cmd_buf(st75256, cmd, d,		\
+					     ARRAY_SIZE(d));		\
+	} while (0)
+
+/*
+ * Sets the display RAM window and writes the data. The x coordinates are in
+ * bytes (pages), y coordinates in pixels (columns), the end is exclusive.
+ */
+static int st75256_write_window(struct st75256_device *st75256,
+				unsigned int x1, unsigned int x2,
+				unsigned int y1, unsigned int y2,
+				const u8 *buf, size_t len)
+{
+	int err = 0;
+
+	st75256_cmd(st75256, &err, ST75256_SET_COL_ADDR, y1, y2 - 1);
+	st75256_cmd(st75256, &err, ST75256_SET_PAGE_ADDR, x1, x2 - 1);
+	st75256_cmd(st75256, &err, ST75256_WRITE_DATA);
+	if (err)
+		return err;
+
+	return st75256_spi_write(st75256, true, buf, len);
+}
+
+static int st75256_clear(struct st75256_device *st75256)
+{
+	const struct st75256_panel *panel = &st75256->panel;
+	unsigned int ppb = st75256->hw_mode == ST75256_MODE_MONO ? 8 : 4;
+	size_t len = panel->width / ppb * panel->height;
+
+	memset(st75256->tx_buf, 0, len);
+
+	return st75256_write_window(st75256, 0, panel->width / ppb,
+				    0, panel->height, st75256->tx_buf, len);
+}
+
+static int st75256_hw_init(struct st75256_device *st75256)
+{
+	const struct st75256_panel *panel = &st75256->panel;
+	int err = 0;
+
+	gpiod_set_value_cansleep(st75256->reset, 1);
+	usleep_range(1000, 2000);
+	gpiod_set_value_cansleep(st75256->reset, 0);
+	msleep(120);
+
+	st75256_cmd(st75256, &err, ST75256_EXT1);
+	st75256_cmd(st75256, &err, ST75256_SLEEP_OUT);
+	if (err)
+		return err;
+	msleep(50);
+	st75256_cmd(st75256, &err, ST75256_DISP_OFF);
+
+	/* Load the factory calibration from OTP */
+	st75256_cmd(st75256, &err, ST75256_EXT2);
+	st75256_cmd(st75256, &err, ST75256_OTP_AUTO_READ_CTRL, 0x9f);
+	st75256_cmd(st75256, &err, ST75256_OTP_WR_RD_CTRL, 0x00);
+	if (err)
+		return err;
+	usleep_range(10000, 11000);
+	st75256_cmd(st75256, &err, ST75256_OTP_READ);
+	if (err)
+		return err;
+	msleep(20);
+	st75256_cmd(st75256, &err, ST75256_OTP_CTRL_OUT);
+
+	/* Frame rate 55.5 Hz */
+	st75256_cmd(st75256, &err, ST75256_FRAME_RATE, 0x09, 0x09, 0x09, 0x09);
+
+	st75256_cmd(st75256, &err, ST75256_EXT1);
+	st75256_cmd(st75256, &err, ST75256_SET_SCAN_DIR,
+		    ST75256_SCAN_PAGE_FIRST | ST75256_SCAN_MX);
+	/* Inverse display, 0 is black */
+	st75256_cmd(st75256, &err, ST75256_DISP_INVERSE);
+	st75256_cmd(st75256, &err, ST75256_PWR_CTRL,
+		    ST75256_PWR_VB | ST75256_PWR_VF | ST75256_PWR_VR);
+	if (err)
+		return err;
+	usleep_range(1000, 2000);
+
+	st75256_cmd(st75256, &err, ST75256_SET_VOP,
+		    panel->vop & 0x3f, (panel->vop >> 6) & 0x07);
+
+	st75256_cmd(st75256, &err, ST75256_EXT2);
+	st75256_cmd(st75256, &err, ST75256_SET_GRAY_LEVEL,
+		    0x00, 0x00, 0x00,
+		    panel->gray_light, panel->gray_light, panel->gray_light,
+		    0x00, 0x00,
+		    panel->gray_dark,
+		    0x00, 0x00,
+		    panel->gray_dark, panel->gray_dark, panel->gray_dark,
+		    0x00, 0x00);
+	st75256_cmd(st75256, &err, ST75256_ANALOG_CIRCUIT, 0x00,
+		    ST75256_BOOSTER_EFF_LEVEL1, ST75256_BIAS_1_12);
+	st75256_cmd(st75256, &err, ST75256_BOOSTER_LEVEL, ST75256_BOOSTER_X10);
+	st75256_cmd(st75256, &err, ST75256_EXT1);
+
+	st75256_cmd(st75256, &err, ST75256_DISP_MODE, ST75256_MODE_GRAY);
+	/* Clock divider, duty, line inversion */
+	st75256_cmd(st75256, &err, ST75256_DISP_CTRL, 0x00, panel->width - 1, 0x01);
+	if (err)
+		return err;
+
+	st75256->hw_mode = ST75256_MODE_GRAY;
+
+	err = st75256_clear(st75256);
+
+	st75256_cmd(st75256, &err, ST75256_DISP_ON);
+
+	return err;
+}
+
+static void st75256_hw_fini(struct st75256_device *st75256)
+{
+	int err = 0;
+
+	st75256_cmd(st75256, &err, ST75256_EXT1);
+	st75256_cmd(st75256, &err, ST75256_DISP_OFF);
+	st75256_cmd(st75256, &err, ST75256_SLEEP_IN);
+
+	gpiod_set_value_cansleep(st75256->reset, 1);
+	st75256->hw_mode = 0;
+}
+
+static int st75256_set_mode(struct st75256_device *st75256, u8 mode)
+{
+	int err = 0;
+
+	st75256_cmd(st75256, &err, ST75256_DISP_MODE, mode);
+	if (!err)
+		st75256->hw_mode = mode;
+
+	return err;
+}
+
+/* Packs 8-bit gray pixels into 2-bit pixels, first pixel in the MSBs */
+static void st75256_pack_gray2(u8 *dst, const u8 *gray, unsigned int pixels)
+{
+	unsigned int i;
+
+	for (i = 0; i < pixels; i += 4) {
+		*dst++ = (gray[i] & 0xc0) |
+			 ((gray[i + 1] & 0xc0) >> 2) |
+			 ((gray[i + 2] & 0xc0) >> 4) |
+			 (gray[i + 3] >> 6);
+	}
+}
+
+static int st75256_fb_blit(struct st75256_device *st75256,
+			   struct drm_framebuffer *fb,
+			   const struct iosys_map *vmap,
+			   const struct drm_plane_state *state,
+			   const struct drm_rect *damage,
+			   struct drm_format_conv_state *fmtcnv_state)
+{
+	unsigned int ppb = st75256->hw_mode == ST75256_MODE_MONO ? 8 : 4;
+	int src_x = state->src.x1 >> 16;
+	int src_y = state->src.y1 >> 16;
+	struct drm_rect dst = *damage;
+	unsigned int row_len;
+	u8 *tx = st75256->tx_buf;
+	int y;
+
+	/* Framebuffer to display coordinates, aligned to whole bytes */
+	drm_rect_translate(&dst, -src_x, -src_y);
+	dst.x1 = round_down(dst.x1, ppb);
+	dst.x2 = min_t(int, round_up(dst.x2, ppb), st75256->panel.width);
+	row_len = drm_rect_width(&dst) / ppb;
+
+	if (fb->format->format == DRM_FORMAT_XRGB8888) {
+		struct iosys_map line = IOSYS_MAP_INIT_VADDR(st75256->line_buf);
+
+		for (y = dst.y1; y < dst.y2; y++) {
+			struct drm_rect clip = DRM_RECT_INIT(dst.x1 + src_x, y + src_y,
+							     drm_rect_width(&dst), 1);
+
+			drm_fb_xrgb8888_to_gray8(&line, NULL, vmap, fb, &clip,
+						 fmtcnv_state);
+			st75256_pack_gray2(tx, st75256->line_buf,
+					   drm_rect_width(&dst));
+			tx += row_len;
+		}
+	} else {
+		const u8 *src = (const u8 *)vmap->vaddr + fb->offsets[0] +
+				(dst.x1 + src_x) / ppb;
+
+		for (y = dst.y1; y < dst.y2; y++) {
+			memcpy(tx, src + (y + src_y) * fb->pitches[0], row_len);
+			tx += row_len;
+		}
+	}
+
+	return st75256_write_window(st75256, dst.x1 / ppb, dst.x2 / ppb,
+				    dst.y1, dst.y2, st75256->tx_buf,
+				    tx - st75256->tx_buf);
+}
+
+static const u32 st75256_formats[] = {
+	DRM_FORMAT_R1,
+	DRM_FORMAT_R2,
+	DRM_FORMAT_XRGB8888,
+};
+
+static int st75256_plane_atomic_check(struct drm_plane *plane,
+				      struct drm_atomic_commit *state)
+{
+	struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, plane);
+	struct drm_shadow_plane_state *shadow_state = to_drm_shadow_plane_state(new_state);
+	struct drm_framebuffer *fb = new_state->fb;
+	struct drm_crtc_state *crtc_state = NULL;
+	int ret;
+
+	if (new_state->crtc)
+		crtc_state = drm_atomic_get_new_crtc_state(state, new_state->crtc);
+
+	ret = drm_atomic_helper_check_plane_state(new_state, crtc_state,
+						  DRM_PLANE_NO_SCALING,
+						  DRM_PLANE_NO_SCALING,
+						  false, false);
+	if (ret || !new_state->visible)
+		return ret;
+
+	if (fb->format->format == DRM_FORMAT_XRGB8888) {
+		/* Line buffer used by drm_fb_xrgb8888_to_gray8() */
+		if (!drm_format_conv_state_reserve(&shadow_state->fmtcnv_state,
+						   drm_rect_width(&new_state->dst) *
+						   fb->format->cpp[0], GFP_KERNEL))
+			return -ENOMEM;
+	} else {
+		/* Packed pixels are copied as whole bytes */
+		unsigned int ppb = 8 / fb->format->depth;
+
+		if ((new_state->src.x1 >> 16) % ppb)
+			return -EINVAL;
+	}
+
+	return 0;
+}
+
+static void st75256_plane_atomic_update(struct drm_plane *plane,
+					struct drm_atomic_commit *state)
+{
+	struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state, plane);
+	struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, plane);
+	struct drm_shadow_plane_state *shadow_state = to_drm_shadow_plane_state(new_state);
+	struct st75256_device *st75256 = drm_to_st75256(plane->dev);
+	struct drm_framebuffer *fb = new_state->fb;
+	struct drm_rect damage;
+	int idx, ret;
+	u8 mode;
+
+	if (!fb || !new_state->visible)
+		return;
+
+	if (!drm_dev_enter(plane->dev, &idx))
+		return;
+
+	mode = fb->format->format == DRM_FORMAT_R1 ?
+	       ST75256_MODE_MONO : ST75256_MODE_GRAY;
+
+	if (mode != st75256->hw_mode) {
+		ret = st75256_set_mode(st75256, mode);
+		if (ret)
+			goto err;
+		/* Display RAM layout changed, repaint everything */
+		drm_rect_fp_to_int(&damage, &new_state->src);
+	} else if (!drm_atomic_helper_damage_merged(old_state, new_state, &damage)) {
+		goto out;
+	}
+
+	ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE);
+	if (ret)
+		goto err;
+
+	ret = st75256_fb_blit(st75256, fb, &shadow_state->data[0], new_state,
+			      &damage, &shadow_state->fmtcnv_state);
+
+	drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
+err:
+	if (ret)
+		drm_err_once(plane->dev, "Failed to update display: %d\n", ret);
+out:
+	drm_dev_exit(idx);
+}
+
+static void st75256_plane_atomic_disable(struct drm_plane *plane,
+					 struct drm_atomic_commit *state)
+{
+	struct st75256_device *st75256 = drm_to_st75256(plane->dev);
+	struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state, plane);
+	struct drm_crtc_state *crtc_state;
+	int idx;
+
+	if (!old_state->crtc)
+		return;
+
+	crtc_state = drm_atomic_get_new_crtc_state(state, old_state->crtc);
+	if (!crtc_state || !crtc_state->active)
+		return;
+
+	if (!drm_dev_enter(plane->dev, &idx))
+		return;
+
+	st75256_clear(st75256);
+
+	drm_dev_exit(idx);
+}
+
+static const struct drm_plane_helper_funcs st75256_plane_helper_funcs = {
+	DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
+	.atomic_check = st75256_plane_atomic_check,
+	.atomic_update = st75256_plane_atomic_update,
+	.atomic_disable = st75256_plane_atomic_disable,
+};
+
+static const struct drm_plane_funcs st75256_plane_funcs = {
+	.update_plane = drm_atomic_helper_update_plane,
+	.disable_plane = drm_atomic_helper_disable_plane,
+	.destroy = drm_plane_cleanup,
+	DRM_GEM_SHADOW_PLANE_FUNCS,
+};
+
+static enum drm_mode_status st75256_crtc_mode_valid(struct drm_crtc *crtc,
+						    const struct drm_display_mode *mode)
+{
+	struct st75256_device *st75256 = drm_to_st75256(crtc->dev);
+
+	return drm_crtc_helper_mode_valid_fixed(crtc, mode, &st75256->mode);
+}
+
+static void st75256_crtc_atomic_enable(struct drm_crtc *crtc,
+				       struct drm_atomic_commit *state)
+{
+	struct st75256_device *st75256 = drm_to_st75256(crtc->dev);
+	int idx, ret;
+
+	if (!drm_dev_enter(crtc->dev, &idx))
+		return;
+
+	ret = st75256_hw_init(st75256);
+	if (ret) {
+		drm_err(crtc->dev, "Failed to initialize display: %d\n", ret);
+		goto out;
+	}
+
+	backlight_enable(st75256->backlight);
+out:
+	drm_dev_exit(idx);
+}
+
+static void st75256_crtc_atomic_disable(struct drm_crtc *crtc,
+					struct drm_atomic_commit *state)
+{
+	struct st75256_device *st75256 = drm_to_st75256(crtc->dev);
+	int idx;
+
+	if (!drm_dev_enter(crtc->dev, &idx))
+		return;
+
+	backlight_disable(st75256->backlight);
+	st75256_hw_fini(st75256);
+
+	drm_dev_exit(idx);
+}
+
+static const struct drm_crtc_helper_funcs st75256_crtc_helper_funcs = {
+	.mode_valid = st75256_crtc_mode_valid,
+	.atomic_check = drm_crtc_helper_atomic_check,
+	.atomic_enable = st75256_crtc_atomic_enable,
+	.atomic_disable = st75256_crtc_atomic_disable,
+};
+
+static const struct drm_crtc_funcs st75256_crtc_funcs = {
+	.atomic_create_state = drm_atomic_helper_crtc_create_state,
+	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
+	.set_config = drm_atomic_helper_set_config,
+	.page_flip = drm_atomic_helper_page_flip,
+	.destroy = drm_crtc_cleanup,
+};
+
+static const struct drm_encoder_funcs st75256_encoder_funcs = {
+	.destroy = drm_encoder_cleanup,
+};
+
+static int st75256_connector_get_modes(struct drm_connector *connector)
+{
+	struct st75256_device *st75256 = drm_to_st75256(connector->dev);
+
+	return drm_connector_helper_get_modes_fixed(connector, &st75256->mode);
+}
+
+static const struct drm_connector_helper_funcs st75256_connector_helper_funcs = {
+	.get_modes = st75256_connector_get_modes,
+};
+
+static const struct drm_connector_funcs st75256_connector_funcs = {
+	.fill_modes = drm_helper_probe_single_connector_modes,
+	.destroy = drm_connector_cleanup,
+	.atomic_create_state = drm_atomic_helper_connector_create_state,
+	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+};
+
+static const struct drm_mode_config_funcs st75256_mode_config_funcs = {
+	.fb_create = drm_gem_fb_create_with_dirty,
+	.atomic_check = drm_atomic_helper_check,
+	.atomic_commit = drm_atomic_helper_commit,
+};
+
+/*
+ * The controller is initialized in the CRTC enable, so the CRTC has to be
+ * enabled before the plane is updated.
+ */
+static const struct drm_mode_config_helper_funcs st75256_mode_config_helper_funcs = {
+	.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
+};
+
+DEFINE_DRM_GEM_FOPS(st75256_fops);
+
+static const struct drm_driver st75256_drm_driver = {
+	DRM_GEM_SHMEM_DRIVER_OPS,
+	DRM_FBDEV_SHMEM_DRIVER_OPS,
+	.name			= DRIVER_NAME,
+	.desc			= DRIVER_DESC,
+	.major			= DRIVER_MAJOR,
+	.minor			= DRIVER_MINOR,
+	.driver_features	= DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET,
+	.fops			= &st75256_fops,
+};
+
+static int st75256_modeset_init(struct st75256_device *st75256)
+{
+	const struct st75256_panel *panel = &st75256->panel;
+	struct drm_device *drm = &st75256->drm;
+	const struct drm_display_mode mode = {
+		DRM_SIMPLE_MODE(panel->width, panel->height,
+				panel->width_mm, panel->height_mm),
+	};
+	int ret;
+
+	ret = drmm_mode_config_init(drm);
+	if (ret)
+		return ret;
+
+	drm_mode_copy(&st75256->mode, &mode);
+
+	drm->mode_config.min_width = mode.hdisplay;
+	drm->mode_config.max_width = max_t(unsigned int, mode.hdisplay,
+					   DRM_SHADOW_PLANE_MAX_WIDTH);
+	drm->mode_config.min_height = mode.vdisplay;
+	drm->mode_config.max_height = max_t(unsigned int, mode.vdisplay,
+					    DRM_SHADOW_PLANE_MAX_HEIGHT);
+	drm->mode_config.preferred_depth = 24;
+	drm->mode_config.funcs = &st75256_mode_config_funcs;
+	drm->mode_config.helper_private = &st75256_mode_config_helper_funcs;
+
+	ret = drm_universal_plane_init(drm, &st75256->plane, 0,
+				       &st75256_plane_funcs,
+				       st75256_formats, ARRAY_SIZE(st75256_formats),
+				       NULL, DRM_PLANE_TYPE_PRIMARY, NULL);
+	if (ret)
+		return ret;
+
+	drm_plane_helper_add(&st75256->plane, &st75256_plane_helper_funcs);
+	drm_plane_enable_fb_damage_clips(&st75256->plane);
+
+	ret = drm_crtc_init_with_planes(drm, &st75256->crtc, &st75256->plane,
+					NULL, &st75256_crtc_funcs, NULL);
+	if (ret)
+		return ret;
+
+	drm_crtc_helper_add(&st75256->crtc, &st75256_crtc_helper_funcs);
+
+	ret = drm_encoder_init(drm, &st75256->encoder, &st75256_encoder_funcs,
+			       DRM_MODE_ENCODER_NONE, NULL);
+	if (ret)
+		return ret;
+
+	st75256->encoder.possible_crtcs = drm_crtc_mask(&st75256->crtc);
+
+	ret = drm_connector_init(drm, &st75256->connector,
+				 &st75256_connector_funcs, DRM_MODE_CONNECTOR_SPI);
+	if (ret)
+		return ret;
+
+	drm_connector_helper_add(&st75256->connector,
+				 &st75256_connector_helper_funcs);
+
+	ret = drm_connector_attach_encoder(&st75256->connector,
+					   &st75256->encoder);
+	if (ret)
+		return ret;
+
+	return drm_mode_config_create_initial_state(drm);
+}
+
+static int st75256_parse_dt(struct st75256_device *st75256)
+{
+	struct st75256_panel *panel = &st75256->panel;
+	struct device *dev = &st75256->spi->dev;
+	u32 gray[2] = { ST75256_GRAY_LIGHT_DEFAULT, ST75256_GRAY_DARK_DEFAULT };
+	struct display_timing dt;
+	u32 vop;
+	int ret;
+
+	ret = of_get_display_timing(dev->of_node, "panel-timing", &dt);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to get panel-timing\n");
+
+	if (!dt.hactive.typ || dt.hactive.typ > ST75256_MAX_WIDTH ||
+	    dt.hactive.typ % 8)
+		return dev_err_probe(dev, -EINVAL,
+				     "hactive %u must be a multiple of 8 up to %u\n",
+				     dt.hactive.typ, ST75256_MAX_WIDTH);
+
+	if (!dt.vactive.typ || dt.vactive.typ > ST75256_MAX_HEIGHT)
+		return dev_err_probe(dev, -EINVAL,
+				     "vactive %u out of range 1-%u\n",
+				     dt.vactive.typ, ST75256_MAX_HEIGHT);
+
+	panel->width = dt.hactive.typ;
+	panel->height = dt.vactive.typ;
+
+	ret = device_property_read_u32(dev, "width-mm", &panel->width_mm);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to read width-mm\n");
+
+	ret = device_property_read_u32(dev, "height-mm", &panel->height_mm);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to read height-mm\n");
+
+	ret = device_property_read_u32(dev, "sitronix,vop", &vop);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to read sitronix,vop\n");
+
+	if (vop < ST75256_VOP_MIN || vop > ST75256_VOP_MAX)
+		return dev_err_probe(dev, -EINVAL,
+				     "sitronix,vop %u out of range %u-%u\n",
+				     vop, ST75256_VOP_MIN, ST75256_VOP_MAX);
+
+	panel->vop = vop;
+
+	ret = device_property_read_u32_array(dev, "sitronix,gray-levels",
+					     gray, ARRAY_SIZE(gray));
+	if (ret && ret != -EINVAL)
+		return dev_err_probe(dev, ret,
+				     "Failed to read sitronix,gray-levels\n");
+
+	if (gray[0] > ST75256_GRAY_LEVEL_MAX || gray[1] > ST75256_GRAY_LEVEL_MAX)
+		return dev_err_probe(dev, -EINVAL,
+				     "sitronix,gray-levels out of range 0-%u\n",
+				     ST75256_GRAY_LEVEL_MAX);
+
+	panel->gray_light = gray[0];
+	panel->gray_dark = gray[1];
+
+	return 0;
+}
+
+static int st75256_probe(struct spi_device *spi)
+{
+	struct device *dev = &spi->dev;
+	const struct st75256_panel *panel;
+	struct st75256_device *st75256;
+	struct drm_device *drm;
+	int ret;
+
+	st75256 = devm_drm_dev_alloc(dev, &st75256_drm_driver,
+				     struct st75256_device, drm);
+	if (IS_ERR(st75256))
+		return PTR_ERR(st75256);
+
+	drm = &st75256->drm;
+	st75256->spi = spi;
+	panel = &st75256->panel;
+
+	ret = st75256_parse_dt(st75256);
+	if (ret)
+		return ret;
+
+	st75256->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(st75256->reset))
+		return dev_err_probe(dev, PTR_ERR(st75256->reset),
+				     "Failed to get reset GPIO\n");
+
+	st75256->dc = devm_gpiod_get(dev, "dc", GPIOD_OUT_LOW);
+	if (IS_ERR(st75256->dc))
+		return dev_err_probe(dev, PTR_ERR(st75256->dc),
+				     "Failed to get D/C GPIO\n");
+
+	st75256->backlight = devm_of_find_backlight(dev);
+	if (IS_ERR(st75256->backlight))
+		return dev_err_probe(dev, PTR_ERR(st75256->backlight),
+				     "Failed to get backlight\n");
+
+	st75256->cmd_buf = devm_kmalloc(dev, ST75256_CMD_BUF_LEN, GFP_KERNEL);
+	/* Full frame in grayscale mode, the larger of the two */
+	st75256->tx_buf = devm_kmalloc(dev, panel->width / 4 * panel->height,
+				       GFP_KERNEL);
+	st75256->line_buf = devm_kmalloc(dev, panel->width, GFP_KERNEL);
+	if (!st75256->cmd_buf || !st75256->tx_buf || !st75256->line_buf)
+		return -ENOMEM;
+
+	spi_set_drvdata(spi, st75256);
+
+	ret = st75256_modeset_init(st75256);
+	if (ret)
+		return ret;
+
+	ret = drm_dev_register(drm, 0);
+	if (ret)
+		return ret;
+
+	drm_client_setup(drm, NULL);
+
+	return 0;
+}
+
+static void st75256_remove(struct spi_device *spi)
+{
+	struct st75256_device *st75256 = spi_get_drvdata(spi);
+
+	drm_dev_unplug(&st75256->drm);
+	drm_atomic_helper_shutdown(&st75256->drm);
+}
+
+static void st75256_shutdown(struct spi_device *spi)
+{
+	struct st75256_device *st75256 = spi_get_drvdata(spi);
+
+	drm_atomic_helper_shutdown(&st75256->drm);
+}
+
+static const struct of_device_id st75256_of_match[] = {
+	{ .compatible = "sitronix,st75256" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, st75256_of_match);
+
+static const struct spi_device_id st75256_spi_id[] = {
+	{ "st75256" },
+	{ }
+};
+MODULE_DEVICE_TABLE(spi, st75256_spi_id);
+
+static struct spi_driver st75256_spi_driver = {
+	.driver = {
+		.name = DRIVER_NAME,
+		.of_match_table = st75256_of_match,
+	},
+	.id_table = st75256_spi_id,
+	.probe = st75256_probe,
+	.remove = st75256_remove,
+	.shutdown = st75256_shutdown,
+};
+module_spi_driver(st75256_spi_driver);
+
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_AUTHOR("Cyril Hrubis <metan@ucw.cz>");
+MODULE_LICENSE("GPL");
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/2] dt-bindings: display: sitronix,st75256: Add DT schema
  2026-12-06 13:13 ` [PATCH v1 1/2] dt-bindings: display: sitronix,st75256: Add DT schema Cyril Hrubis
@ 2026-12-06 13:29   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-06 13:29 UTC (permalink / raw)
  To: Cyril Hrubis, dri-devel, devicetree; +Cc: robh, conor+dt

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] dt-bindings: sitronix,st75256: raw register value in
  sitronix,vop
- [Medium] dt-bindings: sitronix,st75256: driver-derived portrait axes
  and 160-line cap
- [Medium] dt-bindings: sitronix,st75256: unspecified defaults and scale
  in gray-levels
- [Low] dt-bindings: display: commit message cites nonexistent ST75156
  controller
- [Low] dt-bindings: display: sitronix,st75256: redundant panel-common
  properties
--

commit b5f4d738753e02b2804aea36991971dc76f3065b
Author: Cyril Hrubis <metan@ucw.cz>

dt-bindings: display: sitronix,st75256: Add DT schema

This commit adds a Devicetree binding schema for the Sitronix ST75256
monochrome and 4-level grayscale SPI LCD controller.

> The panel is described the same way as for the Sitronix ST75156 and
> ST7571 controllers, the resolution with panel-timing and the physical
> size with width-mm and height-mm.

[Severity: Low]
This isn't a bug, but there is no Sitronix ST75156 binding in the tree;
this looks like a typo for ST7567 (sitronix,st7567.yaml).  Unlike
ST7567 and ST7571, this binding also swaps the axes into portrait
orientation, which would be worth noting here if that convention stays.

> diff --git a/Documentation/devicetree/bindings/display/sitronix,st75256.yaml b/Documentation/devicetree/bindings/display/sitronix,st75256.yaml
> new file mode 100644
> index 0000000000000..a4486507f774c
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/display/sitronix,st75256.yaml

[ ... ]

> +  reset-gpios:
> +    maxItems: 1
> +
> +  dc-gpios:
> +    maxItems: 1
> +    description: Data/command selection (A0) line.
> +
> +  backlight: true
> +  width-mm: true
> +  height-mm: true

[Severity: Low]
Are reset-gpios, backlight, width-mm, and height-mm redundant here?

Because this schema references panel/panel-common.yaml# and uses
unevaluatedProperties: false, all four (including maxItems: 1 on
reset-gpios) are already inherited.  They can be dropped from
properties: while keeping reset-gpios, width-mm, and height-mm required.

> +  panel-timing:
> +    description:
> +      Only hactive and vactive are used and describe the panel resolution.
> +      The hactive has to be a multiple of 8 up to 160, the vactive up to
> +      256. The remaining timings are not applicable and should be zero.

[Severity: Medium]
Should the binding describe the hardware's native axes and 162-line
limit instead of a driver-specific portrait layout and 160-line cap?

The description mandates portrait orientation (width along common lines,
height along segment lines), swapping width-mm/height-mm and
hactive/vactive relative to landscape panels like JLX256128 and sibling
Sitronix bindings (ST7567 and ST7571 map hactive to segment columns).

Capping hactive in prose to a multiple of 8 up to 160 also excludes
valid 161-162 common-line panels and leaves the resolution bounds
unenforced by dtschema.  Scan-order and byte-alignment constraints
belong in the driver rather than the DT ABI.

> +  sitronix,vop:
> +    $ref: /schemas/types.yaml#/definitions/uint32
> +    minimum: 0x55
> +    maximum: 0x168
> +    description:
> +      LCD operating voltage (contrast) setting, V0 = 3.6V + vop * 0.04V. The
> +      optimal value depends on the panel. It is added to the panel specific
> +      offset programmed into the controller OTP by the panel manufacturer.

[Severity: Medium]
Should sitronix,vop use standard voltage units (-microvolt) instead of
a raw controller register value?

Exposing a raw register encoding locks controller arithmetic into the
DT ABI instead of using standard units per writing-bindings.rst.

Because 3.6V is an exact multiple of 0.04V, sitronix,vop-microvolt
(7000000 to 18000000, multipleOf: 40000) maps one-to-one to the
register without rounding error.

> +  sitronix,gray-levels:
> +    $ref: /schemas/types.yaml#/definitions/uint32-array
> +    items:
> +      - description: Light gray level
> +        maximum: 0x1f
> +      - description: Dark gray level
> +        maximum: 0x1f
> +    description:
> +      Gray levels used in the 4-level grayscale mode. If not present, values
> +      calibrated for the JLX256128 and JLX256160 panels are used.

[Severity: Medium]
Does sitronix,gray-levels leave the default values and the 0x00..0x1f
scale direction unspecified?

A generic controller binding shouldn't rely on undisclosed defaults
calibrated for two third-party panels, and without stating whether 0x00
is lightest or darkest, DTS authors can easily invert the two levels
without reading the driver.

Specifying explicit numeric defaults and the scale polarity would make
the ABI self-contained.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206131330.1754178-1-chrubis@suse.cz?part=1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 2/2] drm/sitronix: Add driver for Sitronix ST75256 LCD panels
  2026-12-06 13:13 ` [PATCH v1 2/2] drm/sitronix: Add driver for Sitronix ST75256 LCD panels Cyril Hrubis
@ 2026-12-06 13:35   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-06 13:35 UTC (permalink / raw)
  To: Cyril Hrubis, dri-devel, devicetree; +Cc: robh, conor+dt

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [Critical] drm/sitronix: heap overflow in st75256_fb_blit() on
  fractional src coords
- [High] drm/sitronix: double offset OOB read and raw vmap memcpy in
  st75256_fb_blit()
- [Medium] drm/sitronix: unsafe memcpy() on vmap->vaddr in
  st75256_fb_blit()
- [Medium] drm/sitronix: partial damage clips after CRTC enable leave
  screen blank
- [Medium] drm/sitronix: inconsistent hardware state after
  st75256_hw_init() failure
- [Medium] drm/sitronix: drm_dev_enter() blocks
  st75256_crtc_atomic_disable() on remove
--

commit 0a4d4758a47b4e9c1bc202d6013889ca0bafb0a1
Author: Cyril Hrubis <metan@ucw.cz>

drm/sitronix: Add driver for Sitronix ST75256 LCD panels

This commit adds a DRM driver for Sitronix ST75256 monochrome and
4-level grayscale SPI LCD panels, supporting R1, R2, and XRGB8888
framebuffers with damaged-area updates.

> diff --git a/drivers/gpu/drm/sitronix/st75256.c b/drivers/gpu/drm/sitronix/st75256.c
> new file mode 100644
> index 0000000000000..4a931208cec52
> --- /dev/null
> +++ b/drivers/gpu/drm/sitronix/st75256.c

[ ... ]

> +static int st75256_hw_init(struct st75256_device *st75256)
> +{

[ ... ]

> +	st75256_cmd(st75256, &err, ST75256_DISP_MODE, ST75256_MODE_GRAY);
> +	/* Clock divider, duty, line inversion */
> +	st75256_cmd(st75256, &err, ST75256_DISP_CTRL, 0x00, panel->width - 1, 0x01);
> +	if (err)
> +		return err;
> +
> +	st75256->hw_mode = ST75256_MODE_GRAY;
> +
> +	err = st75256_clear(st75256);
> +
> +	st75256_cmd(st75256, &err, ST75256_DISP_ON);
> +
> +	return err;
> +}

[Severity: Medium]
Can an SPI error during st75256_hw_init() leave the controller in an
inconsistent state for subsequent plane updates?

Early error returns leave reset deasserted, potentially with the internal
booster enabled and ST75256_EXT2 still selected while st75256->hw_mode stays
0.  Because st75256_crtc_atomic_enable() returns void,
st75256_plane_atomic_update() still runs, sees mode != st75256->hw_mode, and
sends opcode 0xf0 without selecting ST75256_EXT1 (which is
ST75256_FRAME_RATE in EXT2 instead of ST75256_DISP_MODE).

In addition, st75256->hw_mode is set to ST75256_MODE_GRAY before
st75256_clear() and ST75256_DISP_ON succeed.  Asserting reset on error,
updating hw_mode only after init succeeds, and bailing out of
st75256_plane_atomic_update() when hw_mode is 0 would keep the state
consistent.

[ ... ]

> +static int st75256_fb_blit(struct st75256_device *st75256,
> +			   struct drm_framebuffer *fb,
> +			   const struct iosys_map *vmap,
> +			   const struct drm_plane_state *state,
> +			   const struct drm_rect *damage,
> +			   struct drm_format_conv_state *fmtcnv_state)
> +{
> +	unsigned int ppb = st75256->hw_mode == ST75256_MODE_MONO ? 8 : 4;
> +	int src_x = state->src.x1 >> 16;
> +	int src_y = state->src.y1 >> 16;
> +	struct drm_rect dst = *damage;
> +	unsigned int row_len;
> +	u8 *tx = st75256->tx_buf;
> +	int y;
> +
> +	/* Framebuffer to display coordinates, aligned to whole bytes */
> +	drm_rect_translate(&dst, -src_x, -src_y);
> +	dst.x1 = round_down(dst.x1, ppb);
> +	dst.x2 = min_t(int, round_up(dst.x2, ppb), st75256->panel.width);
> +	row_len = drm_rect_width(&dst) / ppb;

[Severity: Critical]
Can fractional 16.16 source coordinates overflow st75256->tx_buf here?

st75256_plane_atomic_check() does not reject fractional bits in src.x1 or
src.y1.  When a framebuffer taller than the panel is committed with a
fractional src.y1, drm_atomic_helper_damage_iter_init() rounds plane_src.y1
down and plane_src.y2 up, producing a damage height of panel->height + 1.

Because dst.y2 is not clamped to st75256->panel.height, the row loop runs
panel->height + 1 times and writes panel->width / 4 bytes past the end of
st75256->tx_buf in 2bpp grayscale mode.

On a 256-pixel-tall panel this also truncates y2 - 1 (256) to 0 in
ST75256_SET_COL_ADDR.  Similarly, a damage clip on the trailing fractional
column clamps dst.x1 == dst.x2 == panel->width without returning early,
sending inverted out-of-range page bounds to ST75256_SET_PAGE_ADDR.

[ ... ]

> +	} else {
> +		const u8 *src = (const u8 *)vmap->vaddr + fb->offsets[0] +
> +				(dst.x1 + src_x) / ppb;

[Severity: High]
Does adding fb->offsets[0] here cause an out-of-bounds read for R1 and R2
framebuffers with a non-zero offset?

st75256_plane_atomic_update() passes &shadow_state->data[0] as vmap, which
already had fb->offsets[0] applied by drm_gem_fb_vmap() during
begin_fb_access.  Adding fb->offsets[0] a second time shifts the read by
2 * fb->offsets[0], reading up to fb->offsets[0] bytes past the end of the
mapped GEM buffer and corrupting display output or faulting on a guard page.

> +
> +		for (y = dst.y1; y < dst.y2; y++) {
> +			memcpy(tx, src + (y + src_y) * fb->pitches[0], row_len);
> +			tx += row_len;
> +		}
> +	}

[Severity: Medium]
Is it safe to dereference vmap->vaddr directly with memcpy() here instead of
using iosys_map_memcpy_from()?

DRM_GEM_SHMEM_DRIVER_OPS enables PRIME dma-buf import, and
drm_gem_shmem_vmap_locked() maps imported buffers via dma_buf_vmap(), which
can return an iosys_map with is_iomem set.  Using plain memcpy() on I/O
memory can cause alignment or bus faults on architectures such as arm64.

[ ... ]

> +	mode = fb->format->format == DRM_FORMAT_R1 ?
> +	       ST75256_MODE_MONO : ST75256_MODE_GRAY;
> +
> +	if (mode != st75256->hw_mode) {
> +		ret = st75256_set_mode(st75256, mode);
> +		if (ret)
> +			goto err;
> +		/* Display RAM layout changed, repaint everything */
> +		drm_rect_fp_to_int(&damage, &new_state->src);
> +	} else if (!drm_atomic_helper_damage_merged(old_state, new_state, &damage)) {
> +		goto out;
> +	}

[Severity: Medium]
Can partial FB_DAMAGE_CLIPS after a CRTC enable or modeset leave the rest of
the panel blank?

st75256_crtc_atomic_enable() runs before st75256_plane_atomic_update() and
calls st75256_hw_init(), which clears display RAM and sets hw_mode to
ST75256_MODE_GRAY.  When the plane uses XRGB8888 or R2 with unchanged src
and partial damage clips, mode already matches hw_mode and
drm_atomic_helper_damage_merged() only blits the damaged sub-rectangle onto
the cleared RAM.

Setting new_state->ignore_damage_clips = true in
st75256_plane_atomic_check() when drm_atomic_crtc_needs_modeset(crtc_state)
is true would force a full repaint.

[ ... ]

> +static void st75256_remove(struct spi_device *spi)
> +{
> +	struct st75256_device *st75256 = spi_get_drvdata(spi);
> +
> +	drm_dev_unplug(&st75256->drm);
> +	drm_atomic_helper_shutdown(&st75256->drm);
> +}

[Severity: Medium]
Does calling drm_dev_unplug() before drm_atomic_helper_shutdown() prevent
st75256_crtc_atomic_disable() from powering down the panel on unload?

drm_dev_unplug() sets dev->unplugged = true, so the drm_dev_enter() check in
st75256_crtc_atomic_disable() always returns false during
drm_atomic_helper_shutdown().  As a result, backlight_disable() and
st75256_hw_fini() are skipped on module unload or sysfs unbind, leaving the
panel, its internal booster, and the backlight powered on.

Sibling SPI drivers such as st7586 omit drm_dev_enter()/drm_dev_exit() in
their atomic_disable callback so regular driver unload turns off the display.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206131330.1754178-1-chrubis@suse.cz?part=2

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-06 13:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06 13:13 [PATCH v1 0/2] Add support for Sitronix ST75256 LCD panels Cyril Hrubis
2026-12-06 13:13 ` [PATCH v1 1/2] dt-bindings: display: sitronix,st75256: Add DT schema Cyril Hrubis
2026-12-06 13:29   ` sashiko-bot
2026-12-06 13:13 ` [PATCH v1 2/2] drm/sitronix: Add driver for Sitronix ST75256 LCD panels Cyril Hrubis
2026-12-06 13:35   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox