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.
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/sitronix/st7571-i2c.c b/drivers/gpu/drm/sitronix/st7571-i2c.c
index eec846892962..73e8db25f895 100644
--- a/drivers/gpu/drm/sitronix/st7571-i2c.c
+++ b/drivers/gpu/drm/sitronix/st7571-i2c.c
@@ -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);
--
2.49.0
Hi
Am 10.07.25 um 12:24 schrieb 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.
>
> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
> ---
>
> drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/sitronix/st7571-i2c.c b/drivers/gpu/drm/sitronix/st7571-i2c.c
> index eec846892962..73e8db25f895 100644
> --- a/drivers/gpu/drm/sitronix/st7571-i2c.c
> +++ b/drivers/gpu/drm/sitronix/st7571-i2c.c
> @@ -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
>
> 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);
--
--
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)
Thomas Zimmermann <tzimmermann@suse.de> writes: > Hi > > Am 10.07.25 um 12:24 schrieb 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. >> >> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> >> --- >> >> drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/gpu/drm/sitronix/st7571-i2c.c b/drivers/gpu/drm/sitronix/st7571-i2c.c >> index eec846892962..73e8db25f895 100644 >> --- a/drivers/gpu/drm/sitronix/st7571-i2c.c >> +++ b/drivers/gpu/drm/sitronix/st7571-i2c.c >> @@ -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. > Indeed. > 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! -- Best regards, Javier Martinez Canillas Core Platforms Red Hat
Hi
Am 10.07.25 um 12:24 schrieb 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.
>
> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
> ---
>
> drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/sitronix/st7571-i2c.c b/drivers/gpu/drm/sitronix/st7571-i2c.c
> index eec846892962..73e8db25f895 100644
> --- a/drivers/gpu/drm/sitronix/st7571-i2c.c
> +++ b/drivers/gpu/drm/sitronix/st7571-i2c.c
> @@ -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;
> +
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
> gpiod_set_value_cansleep(st7571->reset, 1);
> fsleep(20);
> gpiod_set_value_cansleep(st7571->reset, 0);
--
--
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)
Thomas Zimmermann <tzimmermann@suse.de> writes:
Hello Thomas,
> Hi
>
> Am 10.07.25 um 12:24 schrieb 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.
>>
>> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
>> ---
>>
>> drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++--
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/sitronix/st7571-i2c.c b/drivers/gpu/drm/sitronix/st7571-i2c.c
>> index eec846892962..73e8db25f895 100644
>> --- a/drivers/gpu/drm/sitronix/st7571-i2c.c
>> +++ b/drivers/gpu/drm/sitronix/st7571-i2c.c
>> @@ -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;
>> +
>
> 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.
--
Best regards,
Javier Martinez Canillas
Core Platforms
Red Hat
On Thu, Jul 10, 2025 at 12:24:34PM +0200, Javier Martinez Canillas wrote: > 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. > > Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> > --- > > drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/sitronix/st7571-i2c.c b/drivers/gpu/drm/sitronix/st7571-i2c.c > index eec846892962..73e8db25f895 100644 > --- a/drivers/gpu/drm/sitronix/st7571-i2c.c > +++ b/drivers/gpu/drm/sitronix/st7571-i2c.c > @@ -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
Marcus Folkesson <marcus.folkesson@gmail.com> writes: Hello Marcus, Thanks for your feedback. > On Thu, Jul 10, 2025 at 12:24:34PM +0200, Javier Martinez Canillas wrote: >> 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. >> >> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> >> --- >> >> drivers/gpu/drm/sitronix/st7571-i2c.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/gpu/drm/sitronix/st7571-i2c.c b/drivers/gpu/drm/sitronix/st7571-i2c.c >> index eec846892962..73e8db25f895 100644 >> --- a/drivers/gpu/drm/sitronix/st7571-i2c.c >> +++ b/drivers/gpu/drm/sitronix/st7571-i2c.c >> @@ -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) > 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 > > Best regards, > Marcus Folkesson -- Best regards, Javier Martinez Canillas Core Platforms Red Hat
Hello Javier, On Thu, Jul 10, 2025 at 01:00:41PM +0200, Javier Martinez Canillas wrote: > > > > 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: > > /** > * 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. Reviewed-by: Marcus Folkesson <marcus.folkesson@gmail.com> Best regards, Marcus Folkesson
Marcus Folkesson <marcus.folkesson@gmail.com> writes: Hello Marcus, > Hello Javier, > > On Thu, Jul 10, 2025 at 01:00:41PM +0200, Javier Martinez Canillas wrote: >> > >> > 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: >> >> /** >> * 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. > > Reviewed-by: Marcus Folkesson <marcus.folkesson@gmail.com> > Thanks for your review! Do you plan to look at the other patches too ? -- Best regards, Javier Martinez Canillas Core Platforms Red Hat
© 2016 - 2026 Red Hat, Inc.