[PATCH] drm/sitronix/st7586: fix bad pixel data due to byte swap

David Lechner posted 1 patch 1 month, 2 weeks ago
drivers/gpu/drm/sitronix/st7586.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
[PATCH] drm/sitronix/st7586: fix bad pixel data due to byte swap
Posted by David Lechner 1 month, 2 weeks ago
Correctly set dbi->write_memory_bpw for the ST7586 driver. This driver
is for a monochrome display that has an unusual data format, so the
default value set in mipi_dbi_spi_init() is not correct simply because
this controller is non-standard.

Previously, we were using dbi->swap_bytes to make the same sort of
workaround, but it was removed in the same commit that added
dbi->write_memory_bpw, so we need to use the latter now to have the
correct behavior.

This fixes every 3 columns of pixels being swapped on the display. There
are 3 pixels per byte, so the byte swap caused this effect.

Fixes: df3fb27a74a4 ("drm/mipi-dbi: Make bits per word configurable for pixel transfers")
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/gpu/drm/sitronix/st7586.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/sitronix/st7586.c b/drivers/gpu/drm/sitronix/st7586.c
index b57ebf37a664..16b6b4e368af 100644
--- a/drivers/gpu/drm/sitronix/st7586.c
+++ b/drivers/gpu/drm/sitronix/st7586.c
@@ -347,6 +347,12 @@ static int st7586_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
+	/*
+	 * Override value set by mipi_dbi_spi_init(). This driver is a bit
+	 * non-standard, so best to set it explicitly here.
+	 */
+	dbi->write_memory_bpw = 8;
+
 	/* Cannot read from this controller via SPI */
 	dbi->read_commands = NULL;
 
@@ -356,15 +362,6 @@ static int st7586_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	/*
-	 * we are using 8-bit data, so we are not actually swapping anything,
-	 * but setting mipi->swap_bytes makes mipi_dbi_typec3_command() do the
-	 * right thing and not use 16-bit transfers (which results in swapped
-	 * bytes on little-endian systems and causes out of order data to be
-	 * sent to the display).
-	 */
-	dbi->swap_bytes = true;
-
 	drm_mode_config_reset(drm);
 
 	ret = drm_dev_register(drm, 0);

---
base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31
change-id: 20260228-drm-mipi-dbi-fix-st7586-byte-swap-f0d03c5f800c

Best regards,
-- 
David Lechner <dlechner@baylibre.com>
Re: [PATCH] drm/sitronix/st7586: fix bad pixel data due to byte swap
Posted by Javier Martinez Canillas 1 month, 1 week ago
David Lechner <dlechner@baylibre.com> writes:

> Correctly set dbi->write_memory_bpw for the ST7586 driver. This driver
> is for a monochrome display that has an unusual data format, so the
> default value set in mipi_dbi_spi_init() is not correct simply because
> this controller is non-standard.
>
> Previously, we were using dbi->swap_bytes to make the same sort of
> workaround, but it was removed in the same commit that added
> dbi->write_memory_bpw, so we need to use the latter now to have the
> correct behavior.
>
> This fixes every 3 columns of pixels being swapped on the display. There
> are 3 pixels per byte, so the byte swap caused this effect.
>
> Fixes: df3fb27a74a4 ("drm/mipi-dbi: Make bits per word configurable for pixel transfers")
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---

The patch looks good to me.

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>

-- 
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
Re: [PATCH] drm/sitronix/st7586: fix bad pixel data due to byte swap
Posted by David Lechner 1 month, 1 week ago
On 3/5/26 4:36 AM, Javier Martinez Canillas wrote:
> David Lechner <dlechner@baylibre.com> writes:
> 
>> Correctly set dbi->write_memory_bpw for the ST7586 driver. This driver
>> is for a monochrome display that has an unusual data format, so the
>> default value set in mipi_dbi_spi_init() is not correct simply because
>> this controller is non-standard.
>>
>> Previously, we were using dbi->swap_bytes to make the same sort of
>> workaround, but it was removed in the same commit that added
>> dbi->write_memory_bpw, so we need to use the latter now to have the
>> correct behavior.
>>
>> This fixes every 3 columns of pixels being swapped on the display. There
>> are 3 pixels per byte, so the byte swap caused this effect.
>>
>> Fixes: df3fb27a74a4 ("drm/mipi-dbi: Make bits per word configurable for pixel transfers")
>> Signed-off-by: David Lechner <dlechner@baylibre.com>
>> ---
> 
> The patch looks good to me.
> 
> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
> 

I pushed this out with: dim push-branch drm-misc-fixes 

(It's been 5 years since I've done that, so hopefully I did it right - I followed
the docs and it all seemed OK to me).
Re: [PATCH] drm/sitronix/st7586: fix bad pixel data due to byte swap
Posted by Javier Martinez Canillas 1 month, 1 week ago
David Lechner <dlechner@baylibre.com> writes:

Hello David,

> On 3/5/26 4:36 AM, Javier Martinez Canillas wrote:
>> David Lechner <dlechner@baylibre.com> writes:
>> 

[...]

>
> I pushed this out with: dim push-branch drm-misc-fixes 
>
> (It's been 5 years since I've done that, so hopefully I did it right - I followed
> the docs and it all seemed OK to me).
>

Yes, you did it correctly AFAICT. Thanks!

-- 
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
Re: [PATCH] drm/sitronix/st7586: fix bad pixel data due to byte swap
Posted by Thomas Zimmermann 1 month, 1 week ago

Am 01.03.26 um 05:30 schrieb David Lechner:
> Correctly set dbi->write_memory_bpw for the ST7586 driver. This driver
> is for a monochrome display that has an unusual data format, so the
> default value set in mipi_dbi_spi_init() is not correct simply because
> this controller is non-standard.
>
> Previously, we were using dbi->swap_bytes to make the same sort of
> workaround, but it was removed in the same commit that added
> dbi->write_memory_bpw, so we need to use the latter now to have the
> correct behavior.
>
> This fixes every 3 columns of pixels being swapped on the display. There
> are 3 pixels per byte, so the byte swap caused this effect.
>
> Fixes: df3fb27a74a4 ("drm/mipi-dbi: Make bits per word configurable for pixel transfers")
> Signed-off-by: David Lechner <dlechner@baylibre.com>

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>

> ---
>   drivers/gpu/drm/sitronix/st7586.c | 15 ++++++---------
>   1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/sitronix/st7586.c b/drivers/gpu/drm/sitronix/st7586.c
> index b57ebf37a664..16b6b4e368af 100644
> --- a/drivers/gpu/drm/sitronix/st7586.c
> +++ b/drivers/gpu/drm/sitronix/st7586.c
> @@ -347,6 +347,12 @@ static int st7586_probe(struct spi_device *spi)
>   	if (ret)
>   		return ret;
>   
> +	/*
> +	 * Override value set by mipi_dbi_spi_init(). This driver is a bit
> +	 * non-standard, so best to set it explicitly here.
> +	 */
> +	dbi->write_memory_bpw = 8;
> +
>   	/* Cannot read from this controller via SPI */
>   	dbi->read_commands = NULL;
>   
> @@ -356,15 +362,6 @@ static int st7586_probe(struct spi_device *spi)
>   	if (ret)
>   		return ret;
>   
> -	/*
> -	 * we are using 8-bit data, so we are not actually swapping anything,
> -	 * but setting mipi->swap_bytes makes mipi_dbi_typec3_command() do the
> -	 * right thing and not use 16-bit transfers (which results in swapped
> -	 * bytes on little-endian systems and causes out of order data to be
> -	 * sent to the display).
> -	 */
> -	dbi->swap_bytes = true;
> -
>   	drm_mode_config_reset(drm);
>   
>   	ret = drm_dev_register(drm, 0);
>
> ---
> base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31
> change-id: 20260228-drm-mipi-dbi-fix-st7586-byte-swap-f0d03c5f800c
>
> Best regards,

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)


Re: [PATCH] drm/sitronix/st7586: fix bad pixel data due to byte swap
Posted by Thomas Zimmermann 1 month, 2 weeks ago
cc Javier

Am 01.03.26 um 05:30 schrieb David Lechner:
> Correctly set dbi->write_memory_bpw for the ST7586 driver. This driver
> is for a monochrome display that has an unusual data format, so the
> default value set in mipi_dbi_spi_init() is not correct simply because
> this controller is non-standard.
>
> Previously, we were using dbi->swap_bytes to make the same sort of
> workaround, but it was removed in the same commit that added
> dbi->write_memory_bpw, so we need to use the latter now to have the
> correct behavior.
>
> This fixes every 3 columns of pixels being swapped on the display. There
> are 3 pixels per byte, so the byte swap caused this effect.
>
> Fixes: df3fb27a74a4 ("drm/mipi-dbi: Make bits per word configurable for pixel transfers")
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
>   drivers/gpu/drm/sitronix/st7586.c | 15 ++++++---------
>   1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/sitronix/st7586.c b/drivers/gpu/drm/sitronix/st7586.c
> index b57ebf37a664..16b6b4e368af 100644
> --- a/drivers/gpu/drm/sitronix/st7586.c
> +++ b/drivers/gpu/drm/sitronix/st7586.c
> @@ -347,6 +347,12 @@ static int st7586_probe(struct spi_device *spi)
>   	if (ret)
>   		return ret;
>   
> +	/*
> +	 * Override value set by mipi_dbi_spi_init(). This driver is a bit
> +	 * non-standard, so best to set it explicitly here.
> +	 */
> +	dbi->write_memory_bpw = 8;
> +
>   	/* Cannot read from this controller via SPI */
>   	dbi->read_commands = NULL;
>   
> @@ -356,15 +362,6 @@ static int st7586_probe(struct spi_device *spi)
>   	if (ret)
>   		return ret;
>   
> -	/*
> -	 * we are using 8-bit data, so we are not actually swapping anything,
> -	 * but setting mipi->swap_bytes makes mipi_dbi_typec3_command() do the
> -	 * right thing and not use 16-bit transfers (which results in swapped
> -	 * bytes on little-endian systems and causes out of order data to be
> -	 * sent to the display).
> -	 */
> -	dbi->swap_bytes = true;
> -
>   	drm_mode_config_reset(drm);
>   
>   	ret = drm_dev_register(drm, 0);
>
> ---
> base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31
> change-id: 20260228-drm-mipi-dbi-fix-st7586-byte-swap-f0d03c5f800c
>
> Best regards,

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)