Skip to contentSkip to conversation

drm/sitronix/st7571-i2c: Add support for the ST7567 Controller

PATCH Superseded Javier Martinez Canillas 4 participants 15 messages Jul 10, 2025 – Jul 14, 2025

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover drm/sitronix/st7571-i2c: Add support for the ST7567 Controller

This patch-series adds support for the Sitronix ST7567 Controller, which is is a monochrome Dot Matrix LCD Controller that has SPI, I2C and parallel interfaces.

The st7571-i2c driver only has support for I2C so displays using other transport interfaces are currently not supported.

The DRM_FORMAT_R1 pixel format and data commands are the same than what is used by the ST7571 controller, so only is needed a different callback that implements the expected initialization sequence for the ST7567 chip.

Patch #1 adds a Device Tree binding schema for the ST7567 Controller.

Patch #2 makes the "reset-gpios" property in the driver to be optional since that isn't needed for the ST7567.

Patch #3 finally extends the st7571-i2c driver to also support the ST7567 device.

Javier Martinez Canillas (3):
dt-bindings: display: Add Sitronix ST7567 LCD Controller drm/sitronix/st7571-i2c: Make the reset GPIO to be optional drm/sitronix/st7571-i2c: Add support for the ST7567 Controller

 .../bindings/display/sitronix,st7567.yaml     | 63 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 drivers/gpu/drm/sitronix/st7571-i2c.c         | 55 +++++++++++++++-
 3 files changed, 117 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/display/sitronix,st7567.yaml
Signature · 4 lines
2.49.0

base-commit: 93eacfcdfbb590d9ed6889d381d5a586dd1ac860
branch: drm-st7567
#1 lore raw

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

Sitronix ST7567 is a monochrome Dot Matrix LCD Controller.

---

 .../bindings/display/sitronix,st7567.yaml     | 63 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 64 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/sitronix,st7567.yaml
Documentation/devicetree/bindings/display/sitronix,st7567.yaml new file +63 -0
new file mode 100644
index 000000000000..e8a5b8ad18fe
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/sitronix,st7567.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sitronix ST7567 Display Controller
+
+maintainers:
+  - Javier Martinez Canillas <[email protected]>
+
+description:
+  Sitronix ST7567 is a driver and controller for monochrome
+  dot matrix LCD panels.
+
+allOf:
+  - $ref: panel/panel-common.yaml#
+
+properties:
+  compatible:
+    const: sitronix,st7567
+
+  reg:
+    maxItems: 1
+
+  width-mm: true
+  height-mm: true
+  panel-timing: true
+
+required:
+  - compatible
+  - reg
+  - width-mm
+  - height-mm
+  - panel-timing
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        display@3f {
+            compatible = "sitronix,st7567";
+            reg = <0x3f>;
+            width-mm = <37>;
+            height-mm = <27>;
+
+            panel-timing {
+                hactive = <128>;
+                vactive = <64>;
+                hback-porch = <0>;
+                vback-porch = <0>;
+                clock-frequency = <0>;
+                hfront-porch = <0>;
+                hsync-len = <0>;
+                vfront-porch = <0>;
+                vsync-len = <0>;
+            };
+          };
+     };
MAINTAINERS +1 -0
index ee2ef9d9db2a..d97e091b1742 100644
@@ -7835,6 +7835,7 @@ F:	drivers/gpu/drm/sitronix/st7586.c
 DRM DRIVER FOR SITRONIX ST7571 PANELS
 M:	Marcus Folkesson <[email protected]>
 S:	Maintained
+F:	Documentation/devicetree/bindings/display/sitronix,st7567.yaml
 F:	Documentation/devicetree/bindings/display/sitronix,st7571.yaml
 F:	drivers/gpu/drm/sitronix/st7571-i2c.c
 
Signature · 1 line
2.49.0
#3 lore raw

PATCH 2/3 drm/sitronix/st7571-i2c: Make the reset GPIO to be optional

In reply to Javier Martinez Canillas

Some Sitronix LCD controllers (such as the ST7567) don't have a reset pin, so lets relax this in the driver and make the reset GPIO to be optional.

The devm_gpiod_get_optional() helper is similar to devm_gpiod_get(), but returns NULL when there isn't a reset-gpios property defined in a DT node.

The DT binding schema for "sitronix,st7571" that require a reset GPIO will enforce the "reset-gpios" to be present, due being a required DT property. But in the driver itself the property can be made optional if not defined.

---

 drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/sitronix/st7571-i2c.c +6 -2
index eec846892962..73e8db25f895 100644
@@ -802,15 +802,19 @@ static int st7571_parse_dt(struct st7571_device *st7571)
 	st7571->nlines = dt.vactive.typ;
 	st7571->ncols = dt.hactive.typ;
 
-	st7571->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	st7571->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
 	if (IS_ERR(st7571->reset))
-		return PTR_ERR(st7571->reset);
+		return dev_err_probe(dev, PTR_ERR(st7571->reset),
+				     "Failed to get reset gpio\n");
 
 	return 0;
 }
 
 static void st7571_reset(struct st7571_device *st7571)
 {
+	if (!st7571->reset)
+		return;
+
 	gpiod_set_value_cansleep(st7571->reset, 1);
 	fsleep(20);
 	gpiod_set_value_cansleep(st7571->reset, 0);
Signature · 1 line
2.49.0
#12 lore raw

PATCH 3/3 drm/sitronix/st7571-i2c: Add support for the ST7567 Controller

In reply to Javier Martinez Canillas

The Sitronix ST7567 is a monochrome Dot Matrix LCD Controller that has SPI, I2C and parallel interfaces. The st7571-i2c driver only has support for I2C so displays using other transport interfaces are currently not supported.

The DRM_FORMAT_R1 pixel format and data commands are the same than what is used by the ST7571 controller, so only is needed a different callback that implements the expected initialization sequence for the ST7567 chip.

---

 drivers/gpu/drm/sitronix/st7571-i2c.c | 47 +++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
drivers/gpu/drm/sitronix/st7571-i2c.c +47 -0
index 73e8db25f895..ea915bd5deeb 100644
@@ -68,6 +68,9 @@
 #define ST7571_SET_COLOR_MODE(c)		(0x10 | FIELD_PREP(GENMASK(0, 0), (c)))
 #define ST7571_COMMAND_SET_NORMAL		(0x00)
 
+/* ST7567 commands */
+#define ST7567_SET_LCD_BIAS(m) (0xa2 | FIELD_PREP(GENMASK(0, 0), (m)))
+
 #define ST7571_PAGE_HEIGHT 8
 
 #define DRIVER_NAME "st7571"
@@ -820,6 +823,37 @@ static void st7571_reset(struct st7571_device *st7571)
 	gpiod_set_value_cansleep(st7571->reset, 0);
 }
 
+static int st7567_lcd_init(struct st7571_device *st7567)
+{
+	/*
+	 * Most of the initialization sequence is taken directly from the
+	 * referential initial code in the ST7567 datasheet.
+	 */
+	u8 commands[] = {
+		ST7571_DISPLAY_OFF,
+
+		ST7567_SET_LCD_BIAS(1),
+
+		ST7571_SET_SEG_SCAN_DIR(0),
+		ST7571_SET_COM_SCAN_DIR(1),
+
+		ST7571_SET_REGULATOR_REG(4),
+		ST7571_SET_CONTRAST_MSB,
+		ST7571_SET_CONTRAST_LSB(0x20),
+
+		ST7571_SET_START_LINE_MSB,
+		ST7571_SET_START_LINE_LSB(st7567->startline),
+
+		ST7571_SET_POWER(0x4),	/* Power Control, VC: ON, VR: OFF, VF: OFF */
+		ST7571_SET_POWER(0x6),	/* Power Control, VC: ON, VR: ON, VF: OFF */
+		ST7571_SET_POWER(0x7),	/* Power Control, VC: ON, VR: ON, VF: ON */
+
+		ST7571_SET_ENTIRE_DISPLAY_ON(0),
+	};
+
+	return st7571_send_command_list(st7567, commands, ARRAY_SIZE(commands));
+}
+
 static int st7571_lcd_init(struct st7571_device *st7571)
 {
 	/*
@@ -964,6 +998,17 @@ static void st7571_remove(struct i2c_client *client)
 	drm_dev_unplug(&st7571->dev);
 }
 
+struct st7571_panel_data st7567_config = {
+	.init = st7567_lcd_init,
+	.constraints = {
+		.min_nlines = 1,
+		.max_nlines = 64,
+		.min_ncols = 128,
+		.max_ncols = 128,
+		.support_grayscale = false,
+	},
+};
+
 struct st7571_panel_data st7571_config = {
 	.init = st7571_lcd_init,
 	.constraints = {
@@ -976,12 +1021,14 @@ struct st7571_panel_data st7571_config = {
 };
 
 static const struct of_device_id st7571_of_match[] = {
+	{ .compatible = "sitronix,st7567", .data = &st7567_config },
 	{ .compatible = "sitronix,st7571", .data = &st7571_config },
 	{},
 };
 MODULE_DEVICE_TABLE(of, st7571_of_match);
 
 static const struct i2c_device_id st7571_id[] = {
+	{ "st7567", 0 },
 	{ "st7571", 0 },
 	{ }
 };
Signature · 1 line
2.49.0
maintainer
#4 lore raw

Re: [PATCH 2/3] drm/sitronix/st7571-i2c: Make the reset GPIO to be optional

In reply to Javier Martinez Canillas
Quoted 21 lines · Javier Martinez Canillas

Some Sitronix LCD controllers (such as the ST7567) don't have a reset pin, so lets relax this in the driver and make the reset GPIO to be optional.

The devm_gpiod_get_optional() helper is similar to devm_gpiod_get(), but returns NULL when there isn't a reset-gpios property defined in a DT node.

The DT binding schema for "sitronix,st7571" that require a reset GPIO will enforce the "reset-gpios" to be present, due being a required DT property. But in the driver itself the property can be made optional if not defined.

---

 drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/sitronix/st7571-i2c.c +0 -0
index eec846892962..73e8db25f895 100644

drivers/gpu/drm/sitronix/st7571-i2c.c static int st7571_parse_dt(struct st7571_device *st7571) · line 808

Quoted 9 lines
drivers/gpu/drm/sitronix/st7571-i2c.c +3 -2
@@ -802,15 +802,19 @@ static int st7571_parse_dt(struct st7571_device *st7571)
 	st7571->nlines = dt.vactive.typ;
 	st7571->ncols = dt.hactive.typ;
 
-	st7571->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	st7571->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
 	if (IS_ERR(st7571->reset))
-		return PTR_ERR(st7571->reset);
+		return dev_err_probe(dev, PTR_ERR(st7571->reset),
+				     "Failed to get reset gpio\n");

devm_gpiod_get_optional() returns -ENOENT when the GPIO is not found, and that is no error we want to propagage upwards.

Maybe something like this instead:
if (IS_ERR(st7571->reset) && IS_ERR(st7571->reset) != -ENOENT)

Best regards,
Marcus Folkesson

#5 lore raw

Re: [PATCH 2/3] drm/sitronix/st7571-i2c: Make the reset GPIO to be optional

Marcus Folkesson <[email protected]> writes:

Hello Marcus,

Thanks for your feedback.

Quoted 35 lines · Javier Martinez Canillas
Quoted 21 lines

Some Sitronix LCD controllers (such as the ST7567) don't have a reset pin, so lets relax this in the driver and make the reset GPIO to be optional.

The devm_gpiod_get_optional() helper is similar to devm_gpiod_get(), but returns NULL when there isn't a reset-gpios property defined in a DT node.

The DT binding schema for "sitronix,st7571" that require a reset GPIO will enforce the "reset-gpios" to be present, due being a required DT property. But in the driver itself the property can be made optional if not defined.

---

 drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/sitronix/st7571-i2c.c +0 -0
index eec846892962..73e8db25f895 100644

drivers/gpu/drm/sitronix/st7571-i2c.c static int st7571_parse_dt(struct st7571_device *st7571) · line 808

Quoted 9 lines
drivers/gpu/drm/sitronix/st7571-i2c.c +3 -2
@@ -802,15 +802,19 @@ static int st7571_parse_dt(struct st7571_device *st7571)
 	st7571->nlines = dt.vactive.typ;
 	st7571->ncols = dt.hactive.typ;
 
-	st7571->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	st7571->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
 	if (IS_ERR(st7571->reset))
-		return PTR_ERR(st7571->reset);
+		return dev_err_probe(dev, PTR_ERR(st7571->reset),
+				     "Failed to get reset gpio\n");

devm_gpiod_get_optional() returns -ENOENT when the GPIO is not found, and that is no error we want to propagage upwards.

Quoted 3 lines

Maybe something like this instead:
if (IS_ERR(st7571->reset) && IS_ERR(st7571->reset) != -ENOENT)

Are you sure about that? As far as I know, that is exactly the difference between gpiod_get() and gpiod_get_optional() variants.

From the gpiod_get_optional() function helper kernel-doc [0]:

/**
* gpiod_get_optional - obtain an optional GPIO for a given GPIO function
* @dev: GPIO consumer, can be NULL for system-global GPIOs
* @con_id: function within the GPIO consumer
* @flags: optional GPIO initialization flags
*
* This is equivalent to gpiod_get(), except that when no GPIO was assigned to
* the requested function it will return NULL. This is convenient for drivers
* that need to handle optional GPIOs.
*
* Returns:
* The GPIO descriptor corresponding to the function @con_id of device
* dev, NULL if no GPIO has been assigned to the requested function, or
* another IS_ERR() code if an error occurred while trying to acquire the GPIO. */

while the gpiod_get() kernel-doc says the following:

/**
* gpiod_get - obtain a GPIO for a given GPIO function
* @dev: GPIO consumer, can be NULL for system-global GPIOs
* @con_id: function within the GPIO consumer
* @flags: optional GPIO initialization flags
*
* Returns:
* The GPIO descriptor corresponding to the function @con_id of device
* dev, -ENOENT if no GPIO has been assigned to the requested function, or
* another IS_ERR() code if an error occurred while trying to acquire the GPIO. */

[0]: https://elixir.bootlin.com/linux/v6.16-rc5/source/drivers/gpio/gpiolib.c#L4755

Quoted 3 lines

Best regards,
Marcus Folkesson

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
maintainer Reviewed-by
#6 lore raw

Re: [PATCH 2/3] drm/sitronix/st7571-i2c: Make the reset GPIO to be optional

Hello Javier,

Quoted 31 lines · Javier Martinez Canillas
Quoted 7 lines

devm_gpiod_get_optional() returns -ENOENT when the GPIO is not found, and that is no error we want to propagage upwards.

Maybe something like this instead:
if (IS_ERR(st7571->reset) && IS_ERR(st7571->reset) != -ENOENT)

Are you sure about that? As far as I know, that is exactly the difference between gpiod_get() and gpiod_get_optional() variants.

From the gpiod_get_optional() function helper kernel-doc [0]:

/**
* gpiod_get_optional - obtain an optional GPIO for a given GPIO function
* @dev: GPIO consumer, can be NULL for system-global GPIOs
* @con_id: function within the GPIO consumer
* @flags: optional GPIO initialization flags
*
* This is equivalent to gpiod_get(), except that when no GPIO was assigned to
* the requested function it will return NULL. This is convenient for drivers
* that need to handle optional GPIOs.
*
* Returns:
* The GPIO descriptor corresponding to the function @con_id of device
* dev, NULL if no GPIO has been assigned to the requested function, or
* another IS_ERR() code if an error occurred while trying to acquire the GPIO. */

while the gpiod_get() kernel-doc says the following:

Quoted 12 lines

/**
* gpiod_get - obtain a GPIO for a given GPIO function
* @dev: GPIO consumer, can be NULL for system-global GPIOs
* @con_id: function within the GPIO consumer
* @flags: optional GPIO initialization flags
*
* Returns:
* The GPIO descriptor corresponding to the function @con_id of device
* dev, -ENOENT if no GPIO has been assigned to the requested function, or
* another IS_ERR() code if an error occurred while trying to acquire the GPIO. */

You are completely righ.

Best regards,
Marcus Folkesson

maintainer Reviewed-by on v1 1/3
#2 lore raw

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

In reply to Javier Martinez Canillas
Quoted 10 lines · Javier Martinez Canillas

Sitronix ST7567 is a monochrome Dot Matrix LCD Controller.

---

 .../bindings/display/sitronix,st7567.yaml     | 63 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 64 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/sitronix,st7567.yaml
#7 lore raw

Re: [PATCH 2/3] drm/sitronix/st7571-i2c: Make the reset GPIO to be optional

In reply to Marcus Folkesson

Marcus Folkesson <[email protected]> writes:

Hello Marcus,

Quoted 47 lines

Hello Javier,

Quoted 31 lines · Javier Martinez Canillas
Quoted 7 lines

devm_gpiod_get_optional() returns -ENOENT when the GPIO is not found, and that is no error we want to propagage upwards.

Maybe something like this instead:
if (IS_ERR(st7571->reset) && IS_ERR(st7571->reset) != -ENOENT)

Are you sure about that? As far as I know, that is exactly the difference between gpiod_get() and gpiod_get_optional() variants.

From the gpiod_get_optional() function helper kernel-doc [0]:

/**
* gpiod_get_optional - obtain an optional GPIO for a given GPIO function
* @dev: GPIO consumer, can be NULL for system-global GPIOs
* @con_id: function within the GPIO consumer
* @flags: optional GPIO initialization flags
*
* This is equivalent to gpiod_get(), except that when no GPIO was assigned to
* the requested function it will return NULL. This is convenient for drivers
* that need to handle optional GPIOs.
*
* Returns:
* The GPIO descriptor corresponding to the function @con_id of device
* dev, NULL if no GPIO has been assigned to the requested function, or
* another IS_ERR() code if an error occurred while trying to acquire the GPIO. */

while the gpiod_get() kernel-doc says the following:

Quoted 12 lines

/**
* gpiod_get - obtain a GPIO for a given GPIO function
* @dev: GPIO consumer, can be NULL for system-global GPIOs
* @con_id: function within the GPIO consumer
* @flags: optional GPIO initialization flags
*
* Returns:
* The GPIO descriptor corresponding to the function @con_id of device
* dev, -ENOENT if no GPIO has been assigned to the requested function, or
* another IS_ERR() code if an error occurred while trying to acquire the GPIO. */

Quoted 4 lines

You are completely righ.

Thanks for your review! Do you plan to look at the other patches too ?

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
maintainer Reviewed-by on the v1 series
#13 lore raw
In reply to Javier Martinez Canillas

Hello Javier,

Quoted 15 lines · Javier Martinez Canillas

This patch-series adds support for the Sitronix ST7567 Controller, which is is a monochrome Dot Matrix LCD Controller that has SPI, I2C and parallel interfaces.

The st7571-i2c driver only has support for I2C so displays using other transport interfaces are currently not supported.

The DRM_FORMAT_R1 pixel format and data commands are the same than what is used by the ST7571 controller, so only is needed a different callback that implements the expected initialization sequence for the ST7567 chip.

Patch #1 adds a Device Tree binding schema for the ST7567 Controller.

Patch #2 makes the "reset-gpios" property in the driver to be optional since that isn't needed for the ST7567.

Quoted 7 lines

Patch #3 finally extends the st7571-i2c driver to also support the ST7567 device.

Javier Martinez Canillas (3):
dt-bindings: display: Add Sitronix ST7567 LCD Controller drm/sitronix/st7571-i2c: Make the reset GPIO to be optional drm/sitronix/st7571-i2c: Add support for the ST7567 Controller

For all patches in this series:

#14 lore raw

Marcus Folkesson <[email protected]> writes:

Hello Marcus,

Quoted 22 lines

Hello Javier,

Quoted 18 lines · Javier Martinez Canillas

This patch-series adds support for the Sitronix ST7567 Controller, which is is a monochrome Dot Matrix LCD Controller that has SPI, I2C and parallel interfaces.

The st7571-i2c driver only has support for I2C so displays using other transport interfaces are currently not supported.

The DRM_FORMAT_R1 pixel format and data commands are the same than what is used by the ST7571 controller, so only is needed a different callback that implements the expected initialization sequence for the ST7567 chip.

Patch #1 adds a Device Tree binding schema for the ST7567 Controller.

Patch #2 makes the "reset-gpios" property in the driver to be optional since that isn't needed for the ST7567.

Patch #3 finally extends the st7571-i2c driver to also support the ST7567 device.

Quoted 8 lines
Quoted 4 lines

Javier Martinez Canillas (3):
dt-bindings: display: Add Sitronix ST7567 LCD Controller drm/sitronix/st7571-i2c: Make the reset GPIO to be optional drm/sitronix/st7571-i2c: Add support for the ST7567 Controller

For all patches in this series:

Thanks! I'll merge this patch series next week then, since I also got an ack from a DT maintainer.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#8 lore raw

Re: [PATCH 2/3] drm/sitronix/st7571-i2c: Make the reset GPIO to be optional

In reply to Javier Martinez Canillas

Hi

Am 10.07.25 um 12:24 schrieb Javier Martinez Canillas:

Quoted 29 lines

Some Sitronix LCD controllers (such as the ST7567) don't have a reset pin, so lets relax this in the driver and make the reset GPIO to be optional.

The devm_gpiod_get_optional() helper is similar to devm_gpiod_get(), but returns NULL when there isn't a reset-gpios property defined in a DT node.

The DT binding schema for "sitronix,st7571" that require a reset GPIO will enforce the "reset-gpios" to be present, due being a required DT property. But in the driver itself the property can be made optional if not defined.

---

  drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/sitronix/st7571-i2c.c +2 -2
index eec846892962..73e8db25f895 100644
@@ -802,15 +802,19 @@ static int st7571_parse_dt(struct st7571_device *st7571)
  	st7571->nlines = dt.vactive.typ;
  	st7571->ncols = dt.hactive.typ;
 
-	st7571->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	st7571->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
  	if (IS_ERR(st7571->reset))
-		return PTR_ERR(st7571->reset);
+		return dev_err_probe(dev, PTR_ERR(st7571->reset),

drivers/gpu/drm/sitronix/st7571-i2c.c static int st7571_parse_dt(struct st7571_device *st7571) · line 817

Quoted 10 lines
drivers/gpu/drm/sitronix/st7571-i2c.c +4 -0
+				     "Failed to get reset gpio\n");
 
  	return 0;
  }
 
  static void st7571_reset(struct st7571_device *st7571)
  {
+	if (!st7571->reset)
+		return;
+

My interpretation of this function is that calling it guarantees a device reset (or an error). So I'd push this test into the caller.

Best regards
Thomas

Quoted 3 lines
drivers/gpu/drm/sitronix/st7571-i2c.c +0 -0
  	gpiod_set_value_cansleep(st7571->reset, 1);
  	fsleep(20);
  	gpiod_set_value_cansleep(st7571->reset, 0);
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#10 lore raw

Re: [PATCH 2/3] drm/sitronix/st7571-i2c: Make the reset GPIO to be optional

In reply to Javier Martinez Canillas

Hi

Am 10.07.25 um 12:24 schrieb Javier Martinez Canillas:

Quoted 21 lines

Some Sitronix LCD controllers (such as the ST7567) don't have a reset pin, so lets relax this in the driver and make the reset GPIO to be optional.

The devm_gpiod_get_optional() helper is similar to devm_gpiod_get(), but returns NULL when there isn't a reset-gpios property defined in a DT node.

The DT binding schema for "sitronix,st7571" that require a reset GPIO will enforce the "reset-gpios" to be present, due being a required DT property. But in the driver itself the property can be made optional if not defined.

---

  drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/sitronix/st7571-i2c.c +0 -0
index eec846892962..73e8db25f895 100644

drivers/gpu/drm/sitronix/st7571-i2c.c static int st7571_parse_dt(struct st7571_device *st7571) · line 808

Quoted 9 lines
drivers/gpu/drm/sitronix/st7571-i2c.c +3 -2
@@ -802,15 +802,19 @@ static int st7571_parse_dt(struct st7571_device *st7571)
  	st7571->nlines = dt.vactive.typ;
  	st7571->ncols = dt.hactive.typ;
 
-	st7571->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	st7571->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
  	if (IS_ERR(st7571->reset))
-		return PTR_ERR(st7571->reset);
+		return dev_err_probe(dev, PTR_ERR(st7571->reset),
+				     "Failed to get reset gpio\n");

There's struct st7571_panel_data. It could store a flag signalling the expected behavior.

With more effort the panel_data could store a dedicated parse_dt pointer for each panel type. ASAICT the st7567 features a subset of the other type. So there might not be much code duplication.

Best regards
Thomas

Quoted 12 lines
drivers/gpu/drm/sitronix/st7571-i2c.c +3 -0
  	return 0;
  }
 
  static void st7571_reset(struct st7571_device *st7571)
  {
+	if (!st7571->reset)
+		return;
+
  	gpiod_set_value_cansleep(st7571->reset, 1);
  	fsleep(20);
  	gpiod_set_value_cansleep(st7571->reset, 0);
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#9 lore raw

Re: [PATCH 2/3] drm/sitronix/st7571-i2c: Make the reset GPIO to be optional

In reply to Thomas Zimmermann

Thomas Zimmermann <[email protected]> writes:

Hello Thomas,

Quoted 37 lines

Hi

Am 10.07.25 um 12:24 schrieb Javier Martinez Canillas:

Quoted 34 lines

Some Sitronix LCD controllers (such as the ST7567) don't have a reset pin, so lets relax this in the driver and make the reset GPIO to be optional.

The devm_gpiod_get_optional() helper is similar to devm_gpiod_get(), but returns NULL when there isn't a reset-gpios property defined in a DT node.

The DT binding schema for "sitronix,st7571" that require a reset GPIO will enforce the "reset-gpios" to be present, due being a required DT property. But in the driver itself the property can be made optional if not defined.

---

  drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/sitronix/st7571-i2c.c +3 -2
index eec846892962..73e8db25f895 100644
@@ -802,15 +802,19 @@ static int st7571_parse_dt(struct st7571_device *st7571)
  	st7571->nlines = dt.vactive.typ;
  	st7571->ncols = dt.hactive.typ;
 
-	st7571->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	st7571->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
  	if (IS_ERR(st7571->reset))
-		return PTR_ERR(st7571->reset);
+		return dev_err_probe(dev, PTR_ERR(st7571->reset),
+				     "Failed to get reset gpio\n");
 
  	return 0;
  }
 
Quoted 9 lines

drivers/gpu/drm/sitronix/st7571-i2c.c static int st7571_parse_dt(struct st7571_device *st7571) · line 817

Quoted 5 lines
drivers/gpu/drm/sitronix/st7571-i2c.c +3 -0
  static void st7571_reset(struct st7571_device *st7571)
  {
+	if (!st7571->reset)
+		return;
+

My interpretation of this function is that calling it guarantees a device reset (or an error). So I'd push this test into the caller.

That's a good point. I'll then do the check in the caller.

Actually... at the end I didn't need a st7571_reset() call for ST7567 since it has its own struct st7571_panel_data .init callback function.

So I can just drop the test for st7571->reset being NULL.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#11 lore raw

Re: [PATCH 2/3] drm/sitronix/st7571-i2c: Make the reset GPIO to be optional

In reply to Thomas Zimmermann
Quoted 27 lines · Thomas Zimmermann

Hi

Am 10.07.25 um 12:24 schrieb Javier Martinez Canillas:

Quoted 24 lines

Some Sitronix LCD controllers (such as the ST7567) don't have a reset pin, so lets relax this in the driver and make the reset GPIO to be optional.

The devm_gpiod_get_optional() helper is similar to devm_gpiod_get(), but returns NULL when there isn't a reset-gpios property defined in a DT node.

The DT binding schema for "sitronix,st7571" that require a reset GPIO will enforce the "reset-gpios" to be present, due being a required DT property. But in the driver itself the property can be made optional if not defined.

---

  drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/sitronix/st7571-i2c.c +0 -0
index eec846892962..73e8db25f895 100644
@@ -802,15 +802,19 @@ static int st7571_parse_dt(struct st7571_device *st7571)
  	st7571->nlines = dt.vactive.typ;
  	st7571->ncols = dt.hactive.typ;
 
Quoted 10 lines

drivers/gpu/drm/sitronix/st7571-i2c.c static int st7571_parse_dt(struct st7571_device *st7571) · line 808

Quoted 6 lines
drivers/gpu/drm/sitronix/st7571-i2c.c +3 -2
-	st7571->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	st7571->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
  	if (IS_ERR(st7571->reset))
-		return PTR_ERR(st7571->reset);
+		return dev_err_probe(dev, PTR_ERR(st7571->reset),
+				     "Failed to get reset gpio\n");

There's struct st7571_panel_data. It could store a flag signalling the expected behavior.

Indeed.

Quoted 4 lines

With more effort the panel_data could store a dedicated parse_dt pointer for each panel type. ASAICT the st7567 features a subset of the other type. So there might not be much code duplication.

This is a good idea too. I think that will do that for v2.

Thanks a lot for your feedback!

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat