Skip to contentSkip to conversation

Add support for Sitronix ST7571 LCD controller

PATCH Superseded Marcus Folkesson 3 participants 12 messages Apr 15, 2025 – Apr 23, 2025

Subsystems (4)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Marcus Folkesson

author maintainer
#0 lore raw

v4 cover Add support for Sitronix ST7571 LCD controller

This series add support for the ST7571 LCD Controller.
It is a 4 gray scale dot matrix LCD controller that supports several interfaces such as SPI, I2C and a 8bit parallell port. The controlelr supports both monochrome and grayscale displays.

This driver only supports the I2C interface, but all common parts could easily be put into a common file to be used with other interfaces. I only have I2C to test with.

The device is a little defiant, it tends to NAK some commands, but all commands takes effect, hence the I2C_M_IGNORE_NAK flag.

---
Changes in v4:
- (dt-binding) Add sitronix,grayscale property
- Describe why ignore_nack may be needed
- Make drm_to_st7571 an inline function
- Add support to clear screen
- Change from C2 to R2
- Add support for XRGB8888
- Use dev_err_probe() where appropriate
- Make Kconfig config depend on MMU
- Introduce device data to prepare for support for other chips
- Add support for drm_encoder_helper_funcs.atomic_en(dis)able
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- (dt-binding) Use 'Controller' rather than 'Panel' in texts
- (dt-binding) Constrain the reg property
- (dt-binding) Remove panel-timing description
- (dt-binding) Change description
- Mostly cosmetic changes in the driver code
- Don't call drm_atomic_helper_shutdown() in remove()
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Reworked pretty much the whole driver to not use obsolete code.
- Use panel and timing bindings to specify resolution and panel size
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Marcus Folkesson (3):
dt-bindings: display: Add Sitronix ST7571 LCD Controller drm/st7571-i2c: add support for Sitronix ST7571 LCD controller
MAINTAINERS: add entry for Sitronix ST7571 LCD Controller

 .../bindings/display/sitronix,st7571.yaml          |  73 ++
 MAINTAINERS                                        |   6 +
 drivers/gpu/drm/tiny/Kconfig                       |  11 +
 drivers/gpu/drm/tiny/Makefile                      |   1 +
 drivers/gpu/drm/tiny/st7571-i2c.c                  | 994 +++++++++++++++++++++
 5 files changed, 1085 insertions(+)

---
base-commit: 1e26c5e28ca5821a824e90dd359556f5e9e7b89f
change-id: 20250401-st7571-9382b9cfc03f

Best regards,

Signature · 1 line
Marcus Folkesson <[email protected]>
author maintainer
#1 lore raw

PATCH v4 1/3 dt-bindings: display: Add Sitronix ST7571 LCD Controller

Sitronix ST7571 is a dot matrix LCD controller supporting both 4bit grayscale and monochrome LCDs.

---
 .../bindings/display/sitronix,st7571.yaml          | 73 ++++++++++++++++++++++
 1 file changed, 73 insertions(+)
Documentation/devicetree/bindings/display/sitronix,st7571.yaml new file +73 -0
new file mode 100644
index 0000000000000000000000000000000000000000..4fea782fccd701f5095a08290c13722a12a58b52
@@ -0,0 +1,73 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/sitronix,st7571.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sitronix ST7571 Display Controller
+
+maintainers:
+  - Marcus Folkesson <[email protected]>
+
+description:
+  Sitronix ST7571 is a driver and controller for 4-level gray
+  scale and monochrome dot matrix LCD panels.
+
+allOf:
+  - $ref: panel/panel-common.yaml#
+
+properties:
+  compatible:
+    const: sitronix,st7571
+
+  reg:
+    maxItems: 1
+
+  sitronix,grayscale:
+    type: boolean
+    description:
+      Display supports 4-level grayscale.
+
+  reset-gpios: true
+  width-mm: true
+  height-mm: true
+  panel-timing: true
+
+required:
+  - compatible
+  - reg
+  - reset-gpios
+  - width-mm
+  - height-mm
+  - panel-timing
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      display@3f {
+        compatible = "sitronix,st7571";
+        reg = <0x3f>;
+        reset-gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
+        width-mm = <37>;
+        height-mm = <27>;
+
+        panel-timing {
+          hactive = <128>;
+          vactive = <96>;
+          hback-porch = <0>;
+          vback-porch = <0>;
+          clock-frequency = <0>;
+          hfront-porch = <0>;
+          hsync-len = <0>;
+          vfront-porch = <0>;
+          vsync-len = <0>;
+        };
+      };
+    };
Signature · 1 line
2.49.0
author maintainer
#6 lore raw

PATCH v4 2/3 drm/st7571-i2c: add support for Sitronix ST7571 LCD controller

In reply to Marcus Folkesson

Sitronix ST7571 is a 4bit gray scale dot matrix LCD controller. The controller has a SPI, I2C and 8bit parallel interface, this driver is for the I2C interface only.

---
 drivers/gpu/drm/tiny/Kconfig      |  11 +
 drivers/gpu/drm/tiny/Makefile     |   1 +
 drivers/gpu/drm/tiny/st7571-i2c.c | 994 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 1006 insertions(+)
drivers/gpu/drm/tiny/Kconfig +11 -0
index 94cbdb1337c07f1628a33599a7130369b9d59d98..e4a55482e3bcd3f6851df1d322a14cbe1f96adfb 100644
@@ -232,6 +232,17 @@ config TINYDRM_ST7586
 
 	  If M is selected the module will be called st7586.
 
+config DRM_ST7571_I2C
+	tristate "DRM support for Sitronix ST7571 display panels (I2C)"
+	depends on DRM && I2C && MMU
+	select DRM_GEM_SHMEM_HELPER
+	select DRM_KMS_HELPER
+	select REGMAP_I2C
+	help
+	  DRM driver for Sitronix ST7571 panels controlled over I2C.
+
+	  if M is selected the module will be called st7571-i2c.
+
 config TINYDRM_ST7735R
 	tristate "DRM support for Sitronix ST7715R/ST7735R display panels"
 	depends on DRM && SPI
drivers/gpu/drm/tiny/Makefile +1 -0
index 60816d2eb4ff93b87228ed8eadd60a0a33a1144b..eab7568c92c880cfdf7c2f0b9c4bfac4685dbe95 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_DRM_GM12U320)		+= gm12u320.o
 obj-$(CONFIG_DRM_OFDRM)			+= ofdrm.o
 obj-$(CONFIG_DRM_PANEL_MIPI_DBI)	+= panel-mipi-dbi.o
 obj-$(CONFIG_DRM_SIMPLEDRM)		+= simpledrm.o
+obj-$(CONFIG_DRM_ST7571_I2C)		+= st7571-i2c.o
 obj-$(CONFIG_TINYDRM_HX8357D)		+= hx8357d.o
 obj-$(CONFIG_TINYDRM_ILI9163)		+= ili9163.o
 obj-$(CONFIG_TINYDRM_ILI9225)		+= ili9225.o
drivers/gpu/drm/tiny/st7571-i2c.c new file +994 -0

994 lines not on this page · raw message

Signature · 1 line
2.49.0
author maintainer
#9 lore raw

PATCH v4 3/3 MAINTAINERS: add entry for Sitronix ST7571 LCD Controller

In reply to Marcus Folkesson

Add MAINTAINERS entry for the Sitronix ST7571 dot matrix LCD controller.

---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
index 889bd4a59551c9bc125f94944a6e1c7e3ef2de83..eeae24fda846b9f63400ebb08c3fa7f02f3f4b19 100644
@@ -7572,6 +7572,12 @@ T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
 F:	Documentation/devicetree/bindings/display/sitronix,st7586.txt
 F:	drivers/gpu/drm/tiny/st7586.c
 
+DRM DRIVER FOR SITRONIX ST7571 PANELS
+M:	Marcus Folkesson <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/display/sitronix,st7571.yaml
+F:	drivers/gpu/drm/tiny/st7571-i2c.c
+
 DRM DRIVER FOR SITRONIX ST7701 PANELS
 M:	Jagan Teki <[email protected]>
 S:	Maintained
Signature · 1 line
2.49.0
#11 lore raw
In reply to Marcus Folkesson
Quoted 9 lines · Marcus Folkesson

This series add support for the ST7571 LCD Controller.
It is a 4 gray scale dot matrix LCD controller that supports several interfaces such as SPI, I2C and a 8bit parallell port. The controlelr supports both monochrome and grayscale displays.

This driver only supports the I2C interface, but all common parts could easily be put into a common file to be used with other interfaces. I only have I2C to test with.

Quoted 7 lines

The device is a little defiant, it tends to NAK some commands, but all commands takes effect, hence the I2C_M_IGNORE_NAK flag.

---
Changes in v4:
- (dt-binding) Add sitronix,grayscale property

Mention that this is the reason of dropping Review.

Best regards,
Krzysztof

#2 lore raw

Re: [PATCH v4 1/3] dt-bindings: display: Add Sitronix ST7571 LCD Controller

In reply to Marcus Folkesson
Quoted 13 lines · Marcus Folkesson
Documentation/devicetree/bindings/display/sitronix,st7571.yaml new file +13 -0
+title: Sitronix ST7571 Display Controller
+
+maintainers:
+  - Marcus Folkesson <[email protected]>
+
+description:
+  Sitronix ST7571 is a driver and controller for 4-level gray
+  scale and monochrome dot matrix LCD panels.
+
+allOf:
+  - $ref: panel/panel-common.yaml#
+
+properties:

Documentation/devicetree/bindings/display/sitronix,st7571.yaml line 29

Quoted 10 lines
Documentation/devicetree/bindings/display/sitronix,st7571.yaml new file +10 -0
+  compatible:
+    const: sitronix,st7571
+
+  reg:
+    maxItems: 1
+
+  sitronix,grayscale:
+    type: boolean
+    description:
+      Display supports 4-level grayscale.

That's fully deducible from compatible, no? Or does it depend on actual panel, but then what else depends on the panel?

Best regards,
Krzysztof

author maintainer
#3 lore raw

Re: [PATCH v4 1/3] dt-bindings: display: Add Sitronix ST7571 LCD Controller

Hi Krzysztof,

Quoted 19 lines · Krzysztof Kozlowski
Quoted 18 lines · Marcus Folkesson
Documentation/devicetree/bindings/display/sitronix,st7571.yaml new file +18 -0
+title: Sitronix ST7571 Display Controller
+
+maintainers:
+  - Marcus Folkesson <[email protected]>
+
+description:
+  Sitronix ST7571 is a driver and controller for 4-level gray
+  scale and monochrome dot matrix LCD panels.
+
+allOf:
+  - $ref: panel/panel-common.yaml#
+
+properties:
+  compatible:
+    const: sitronix,st7571
+
+  reg:
+    maxItems: 1
Quoted 8 lines

Documentation/devicetree/bindings/display/sitronix,st7571.yaml line 29

Quoted 5 lines
Documentation/devicetree/bindings/display/sitronix,st7571.yaml new file +5 -0
+
+  sitronix,grayscale:
+    type: boolean
+    description:
+      Display supports 4-level grayscale.

That's fully deducible from compatible, no? Or does it depend on actual panel, but then what else depends on the panel?

No it is not, the ST7571 is only the controller and some properties depends on the connected LCD.

ST7571 supports both grayscale and monochrome LCDs but has no way to know what is connected.

Other properties that depends on the LCD are:
panel-timing.hactive
panel-timing.vactive
panel-timing.vfront-porch

In the first revisons of the driver, I thought I could let the grayscale and monochrome setting depends on which pixel format that where used, but that was not the case.

Quoted 3 lines

Best regards,
Krzysztof

Best regards,
Marcus Folkesson

Reviewed-by on v4 3/3
#10 lore raw

Re: [PATCH v4 3/3] MAINTAINERS: add entry for Sitronix ST7571 LCD Controller

In reply to Marcus Folkesson

Marcus Folkesson <[email protected]> writes:

Hello Marcus,

Quoted 14 lines

Add MAINTAINERS entry for the Sitronix ST7571 dot matrix LCD controller.

---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)
MAINTAINERS +0 -0
index 889bd4a59551c9bc125f94944a6e1c7e3ef2de83..eeae24fda846b9f63400ebb08c3fa7f02f3f4b19 100644

MAINTAINERS T: git https://gitlab.freedesktop.org/drm/misc/kernel.git · line 7580

Quoted 9 lines
MAINTAINERS +6 -0
@@ -7572,6 +7572,12 @@ T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
 F:	Documentation/devicetree/bindings/display/sitronix,st7586.txt
 F:	drivers/gpu/drm/tiny/st7586.c
 
+DRM DRIVER FOR SITRONIX ST7571 PANELS
+M:	Marcus Folkesson <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/display/sitronix,st7571.yaml
+F:	drivers/gpu/drm/tiny/st7571-i2c.c
+
Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
Reviewed-by on v4 1/3
#5 lore raw

Re: [PATCH v4 1/3] dt-bindings: display: Add Sitronix ST7571 LCD Controller

In reply to Marcus Folkesson
Quoted 5 lines · Marcus Folkesson

Sitronix ST7571 is a dot matrix LCD controller supporting both 4bit grayscale and monochrome LCDs.

---

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
Reviewed-by on v4 2/3
#7 lore raw

Re: [PATCH v4 2/3] drm/st7571-i2c: add support for Sitronix ST7571 LCD controller

In reply to Marcus Folkesson

Marcus Folkesson <[email protected]> writes:

Hello Marcus,

Quoted 7 lines

Sitronix ST7571 is a 4bit gray scale dot matrix LCD controller. The controller has a SPI, I2C and 8bit parallel interface, this driver is for the I2C interface only.

---

[...]

drivers/gpu/drm/tiny/st7571-i2c.c line 48

Quoted 5 lines
drivers/gpu/drm/tiny/st7571-i2c.c new file +5 -0
+#define ST7571_SET_COLUMN_LSB(c)		(0x00 | ((c) & 0xf))
+#define ST7571_SET_COLUMN_MSB(c)		(0x10 | ((c) >> 4))
+#define ST7571_SET_COM0_LSB(x)			((x) & 0x7f)
+#define ST7571_SET_COM0_MSB			(0x44)
+#define ST7571_SET_COM_SCAN_DIR(d)		(0xc0 | (((d) << 3) & 0x8))

You could also use the GENMASK() and FIELD_PREP() macros for these, e.g:

#define ST7571_SET_COLUMN_LSB(c) (0x00 | FIELD_PREP(GENMASK(3, 0), (c)))
#define ST7571_SET_COLUMN_MSB(c) (0x10 | FIELD_PREP(GENMASK(3, 0), (c) >> 4))
#define ST7571_SET_COM0_LSB(x) (FIELD_PREP(GENMASK(6, 0), (x)))
#define ST7571_SET_COM0_MSB (0x44)
#define ST7571_SET_COM_SCAN_DIR(d) (0xc0 | FIELD_PREP(GENMASK(3, 3), (d)))

[...]

Maybe a comment here that this function only exists due regmap expecting both a .write and .read handler even for devices that are write only, e.g:

/* The st7571 driver does not read registers but regmap expects a .read */

Quoted 6 lines
drivers/gpu/drm/tiny/st7571-i2c.c new file +6 -0
+static int st7571_regmap_read(void *context, const void *reg_buf,
+			       size_t reg_size, void *val_buf, size_t val_size)
+{
+	return -EOPNOTSUPP;
+}
+

[...]

Quoted 2 lines
(quoted diff) +2 -0
+static int st7571_fb_update_rect_grayscale(struct drm_framebuffer *fb, struct drm_rect *rect)
+{

[...]

drivers/gpu/drm/tiny/st7571-i2c.c line 380

Quoted 11 lines
drivers/gpu/drm/tiny/st7571-i2c.c new file +11 -0
+	for (int y = rect->y1; y < rect->y2; y += ST7571_PAGE_HEIGHT) {
+		for (int x = x1; x < x2; x++)
+			row[x] = st7571_transform_xy(st7571->hwbuf, x, y);
+
+		st7571_set_position(st7571, rect->x1, y);
+
+		/* TODO: Investige why we can't write multiple bytes at once */
+		for (int x = x1; x < x2; x++) {
+			regmap_bulk_write(st7571->regmap, ST7571_DATA_MODE, row + x, 1);
+
+			/* Write monochrome formats twice */

Why this is needed ?

drivers/gpu/drm/tiny/st7571-i2c.c line 388

Quoted 8 lines
drivers/gpu/drm/tiny/st7571-i2c.c new file +8 -0
+			if (format == DRM_FORMAT_R1 || format == DRM_FORMAT_XRGB8888)
+				regmap_bulk_write(st7571->regmap, ST7571_DATA_MODE, row + x, 1);
+		}
+	}
+
+	return 0;
+}
+

The driver looks great to me now, thanks a lot for taking my comments into account!

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
author maintainer
#8 lore raw

Re: [PATCH v4 2/3] drm/st7571-i2c: add support for Sitronix ST7571 LCD controller

Hello Javier,

Quoted 22 lines · Javier Martinez Canillas

Marcus Folkesson <[email protected]> writes:

Hello Marcus,

Quoted 7 lines

Sitronix ST7571 is a 4bit gray scale dot matrix LCD controller. The controller has a SPI, I2C and 8bit parallel interface, this driver is for the I2C interface only.

---

[...]

drivers/gpu/drm/tiny/st7571-i2c.c line 48

Quoted 5 lines
drivers/gpu/drm/tiny/st7571-i2c.c new file +5 -0
+#define ST7571_SET_COLUMN_LSB(c)		(0x00 | ((c) & 0xf))
+#define ST7571_SET_COLUMN_MSB(c)		(0x10 | ((c) >> 4))
+#define ST7571_SET_COM0_LSB(x)			((x) & 0x7f)
+#define ST7571_SET_COM0_MSB			(0x44)
+#define ST7571_SET_COM_SCAN_DIR(d)		(0xc0 | (((d) << 3) & 0x8))

You could also use the GENMASK() and FIELD_PREP() macros for these, e.g:

Quoted 5 lines

#define ST7571_SET_COLUMN_LSB(c) (0x00 | FIELD_PREP(GENMASK(3, 0), (c)))
#define ST7571_SET_COLUMN_MSB(c) (0x10 | FIELD_PREP(GENMASK(3, 0), (c) >> 4))
#define ST7571_SET_COM0_LSB(x) (FIELD_PREP(GENMASK(6, 0), (x)))
#define ST7571_SET_COM0_MSB (0x44)
#define ST7571_SET_COM_SCAN_DIR(d) (0xc0 | FIELD_PREP(GENMASK(3, 3), (d)))

That looks better, I will change to use those macros.

Quoted 5 lines

[...]

Maybe a comment here that this function only exists due regmap expecting both a .write and .read handler even for devices that are write only, e.g:

Sure

Quoted 16 lines

/* The st7571 driver does not read registers but regmap expects a .read */

Quoted 6 lines
drivers/gpu/drm/tiny/st7571-i2c.c new file +6 -0
+static int st7571_regmap_read(void *context, const void *reg_buf,
+			       size_t reg_size, void *val_buf, size_t val_size)
+{
+	return -EOPNOTSUPP;
+}
+

[...]

Quoted 2 lines
(quoted diff) +2 -0
+static int st7571_fb_update_rect_grayscale(struct drm_framebuffer *fb, struct drm_rect *rect)
+{

[...]

Quoted 13 lines

drivers/gpu/drm/tiny/st7571-i2c.c line 380

Quoted 11 lines
drivers/gpu/drm/tiny/st7571-i2c.c new file +11 -0
+	for (int y = rect->y1; y < rect->y2; y += ST7571_PAGE_HEIGHT) {
+		for (int x = x1; x < x2; x++)
+			row[x] = st7571_transform_xy(st7571->hwbuf, x, y);
+
+		st7571_set_position(st7571, rect->x1, y);
+
+		/* TODO: Investige why we can't write multiple bytes at once */
+		for (int x = x1; x < x2; x++) {
+			regmap_bulk_write(st7571->regmap, ST7571_DATA_MODE, row + x, 1);
+
+			/* Write monochrome formats twice */

Why this is needed ?

If the display is 4bit grayscale it still expect each pixel to be written as two bits. The mapping is as follows:
0 0 => White
0 1 => Light gray
1 0 => Dark gray
1 1 => Black

So here I write the data twice to get a black&white image for monochrome formats.
This is not tested though, I only have a monochrome display to test with.

I will extend the comment to explain this.

Quoted 11 lines

drivers/gpu/drm/tiny/st7571-i2c.c line 388

Quoted 9 lines
drivers/gpu/drm/tiny/st7571-i2c.c new file +8 -0
+			if (format == DRM_FORMAT_R1 || format == DRM_FORMAT_XRGB8888)
+				regmap_bulk_write(st7571->regmap, ST7571_DATA_MODE, row + x, 1);
+		}
+	}
+
+	return 0;
+}
+

The driver looks great to me now, thanks a lot for taking my comments into account!

Thanks!

Quoted 10 lines
Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat

Best regards,
Marcus Folkesson