From: Elkin Cruz <elkin@google.com>
To: Iker Pedrosa <ikerpedrosam@gmail.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, irogers@google.com,
Elkin Cruz <elkin@google.com>,
stable@vger.kernel.org
Subject: [PATCH 1/3] drm/sitronix: st7920: Use DMA-safe serialized TX buffer for SPI writes
Date: Wed, 25 Nov 2026 22:25:11 +0000 [thread overview]
Message-ID: <20261125222513.1446099-2-elkin@google.com> (raw)
In-Reply-To: <20261125222513.1446099-1-elkin@google.com>
In st7920_spi_write(), u8 reg[CMD_SIZE] is allocated on the stack and
passed directly to spi_write(), violating SPI DMA safety requirements
when CONFIG_VMAP_STACK is enabled or an IOMMU is in use.
Embed an ARCH_DMA_MINALIGN-aligned TX buffer at the end of
struct st7920_device protected by a DRM-managed mutex, and pass
st7920 to st7920_spi_write().
Fixes: 88b09229f34a ("drm: Add driver for Sitronix ST7920 LCD displays")
Cc: stable@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---
drivers/gpu/drm/sitronix/st7920.c | 43 +++++++++++++++++++++----------
1 file changed, 30 insertions(+), 13 deletions(-)
diff --git a/drivers/gpu/drm/sitronix/st7920.c b/drivers/gpu/drm/sitronix/st7920.c
index 616d83387d31..091e80d8bda5 100644
--- a/drivers/gpu/drm/sitronix/st7920.c
+++ b/drivers/gpu/drm/sitronix/st7920.c
@@ -7,9 +7,12 @@
*/
#include <linux/bitrev.h>
+#include <linux/cache.h>
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/regmap.h>
#include <linux/spi/spi.h>
@@ -24,6 +27,7 @@
#include <drm/drm_gem_atomic_helper.h>
#include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_gem_shmem_helper.h>
+#include <drm/drm_managed.h>
#include <drm/drm_plane.h>
#include <drm/drm_print.h>
#include <drm/drm_probe_helper.h>
@@ -86,6 +90,10 @@ struct st7920_device {
u32 height;
u32 width;
+
+ /* Serializes SPI command and GDRAM transfers using tx_buf */
+ struct mutex tx_lock;
+ u8 tx_buf[CMD_SIZE] __aligned(ARCH_DMA_MINALIGN);
};
struct st7920_plane_state {
@@ -165,16 +173,21 @@ static int st7920_store_others(int cmd, const void *data, u8 *reg)
return i;
}
-static void st7920_spi_write(struct spi_device *spi, int cmd, const void *data,
- int delay_us, struct spi7920_error *err)
+static void st7920_spi_write(struct st7920_device *st7920, int cmd,
+ const void *data, int delay_us,
+ struct spi7920_error *err)
{
- u8 reg[CMD_SIZE] = {0};
+ u8 *reg = st7920->tx_buf;
int size = 0;
int ret;
if (err->errno)
return;
+ guard(mutex)(&st7920->tx_lock);
+
+ memset(reg, 0, CMD_SIZE);
+
/*
* First the sync bits are sent: 11111WS0.
* Where W is the read/write (RW) bit and S is the register/data (RS) bit.
@@ -190,7 +203,7 @@ static void st7920_spi_write(struct spi_device *spi, int cmd, const void *data,
else
size = st7920_store_others(cmd, data, reg);
- ret = spi_write(spi, reg, size);
+ ret = spi_write(st7920->spi, reg, size);
if (ret) {
err->errno = ret;
return;
@@ -232,14 +245,14 @@ MODULE_DEVICE_TABLE(spi, st7920_spi_id);
static void st7920_power_on(struct st7920_device *st7920,
struct spi7920_error *err)
{
- st7920_spi_write(st7920->spi, SET_DISPLAY_ON, NULL, 72, err);
+ st7920_spi_write(st7920, SET_DISPLAY_ON, NULL, 72, err);
}
static void st7920_power_off(struct st7920_device *st7920,
struct spi7920_error *err)
{
- st7920_spi_write(st7920->spi, SET_DISPLAY_CLEAR, NULL, 1600, err);
- st7920_spi_write(st7920->spi, SET_DISPLAY_OFF, NULL, 72, err);
+ st7920_spi_write(st7920, SET_DISPLAY_CLEAR, NULL, 1600, err);
+ st7920_spi_write(st7920, SET_DISPLAY_OFF, NULL, 72, err);
}
static void st7920_hw_reset(struct st7920_device *st7920)
@@ -257,10 +270,10 @@ static int st7920_init(struct st7920_device *st7920)
{
struct spi7920_error err = {0};
- st7920_spi_write(st7920->spi, SET_BASIC_INSTRUCTION_SET, NULL, 72, &err);
+ st7920_spi_write(st7920, SET_BASIC_INSTRUCTION_SET, NULL, 72, &err);
st7920_power_on(st7920, &err);
- st7920_spi_write(st7920->spi, SET_GRAPHICS_DISPLAY, NULL, 72, &err);
- st7920_spi_write(st7920->spi, SET_DISPLAY_CLEAR, NULL, 1600, &err);
+ st7920_spi_write(st7920, SET_GRAPHICS_DISPLAY, NULL, 72, &err);
+ st7920_spi_write(st7920, SET_DISPLAY_CLEAR, NULL, 1600, &err);
return err.errno;
}
@@ -296,8 +309,8 @@ static int st7920_update_rect(struct st7920_device *st7920,
data_array[array_idx++] = line_buffer[j];
}
- st7920_spi_write(st7920->spi, SET_GDRAM_ADDRESS, &i, 72, &err);
- st7920_spi_write(st7920->spi, SET_GDRAM_DATA, line_buffer, 72, &err);
+ st7920_spi_write(st7920, SET_GDRAM_ADDRESS, &i, 72, &err);
+ st7920_spi_write(st7920, SET_GDRAM_DATA, line_buffer, 72, &err);
}
return err.errno;
@@ -309,7 +322,7 @@ static void st7920_clear_screen(struct st7920_device *st7920, u8 *data_array)
memset(data_array, 0, BYTES_IN_DISPLAY);
- st7920_spi_write(st7920->spi, SET_DISPLAY_CLEAR, NULL, 1600, &err);
+ st7920_spi_write(st7920, SET_DISPLAY_CLEAR, NULL, 1600, &err);
}
static int st7920_fb_blit_rect(struct drm_framebuffer *fb,
@@ -812,6 +825,10 @@ static int st7920_probe(struct spi_device *spi)
st7920->width = ST7920_DEFAULT_WIDTH;
st7920->height = ST7920_DEFAULT_HEIGHT;
+ ret = drmm_mutex_init(drm, &st7920->tx_lock);
+ if (ret)
+ return ret;
+
st7920->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
if (IS_ERR(st7920->reset_gpio)) {
ret = PTR_ERR(st7920->reset_gpio);
--
2.56.1.839.g22a8290db9-goog
next parent reply other threads:[~2026-11-25 22:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261125222513.1446099-1-elkin@google.com>
2026-11-25 22:25 ` Elkin Cruz [this message]
2026-11-25 22:25 ` [PATCH 2/3] drm/sitronix: st7920: Check drm_dev_enter() in crtc atomic disable Elkin Cruz
2026-11-25 22:25 ` [PATCH 3/3] drm/sitronix: st7920: Pass u8 row address when setting GDRAM address Elkin Cruz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125222513.1446099-2-elkin@google.com \
--to=elkin@google.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ikerpedrosam@gmail.com \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=stable@vger.kernel.org \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox