diff options
| author | Amit Barzilai <amit.barzilai22@gmail.com> | 2026-09-14 11:59:30 +0300 |
|---|---|---|
| committer | Javier Martinez Canillas <javierm@redhat.com> | 2026-09-14 11:14:38 +0200 |
| commit | 3a1de89b73d44231531871050e31e7196e89ecef (patch) | |
| tree | cbdc6740a9862240c2bc9643f29434393e8b3cab /drivers/gpu/drm/solomon/ssd130x.c | |
| parent | 19713453f0ca509d36a5e82a56ba9a009d411ed9 (diff) | |
| download | linux-next-3a1de89b73d44231531871050e31e7196e89ecef.tar.gz linux-next-3a1de89b73d44231531871050e31e7196e89ecef.zip | |
drm/ssd130x: Implement ssd130x_write_cmd() on top of ssd130x_write_cmds()
ssd130x_write_cmd() and ssd130x_write_cmds() each carried their own
regmap_write() loop over SSD13XX_COMMAND, differing only in how the caller
supplies the bytes.
Turn ssd130x_write_cmd() into a thin variadic wrapper that collects its
arguments into a small stack buffer and defers to ssd130x_write_cmds(), and
move the protocol comment onto the latter, which is where the loop now
lives.
No functional change: the bytes sent and the bus transactions used to send
them are identical for every chip on both the I2C and SPI transports.
Assisted-by: LLM
Signed-off-by: Amit Barzilai <amit.barzilai22@gmail.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patch.msgid.link/20260914085931.66857-6-amit.barzilai22@gmail.com
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/solomon/ssd130x.c')
| -rw-r--r-- | drivers/gpu/drm/solomon/ssd130x.c | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ssd130x.c index 1d834be6243b..fd13250ef56a 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -258,41 +258,12 @@ static int ssd130x_write_data(struct ssd130x_device *ssd130x, const u8 *values, } /* - * Helper to write command (SSD13XX_COMMAND). The fist variadic argument - * is the command to write and the following are the command options. + * Helper to write a command (SSD13XX_COMMAND) from a buffer. The first byte + * is the command opcode and the following ones are its parameters. * - * Note that the ssd13xx protocol requires each command and option to be - * written as a SSD13XX_COMMAND device register value. That is why a call - * to regmap_write(..., SSD13XX_COMMAND, ...) is done for each argument. - */ -static int ssd130x_write_cmd(struct ssd130x_device *ssd130x, int count, - /* u8 cmd, u8 option, ... */...) -{ - va_list ap; - u8 value; - int ret; - - va_start(ap, count); - - do { - value = va_arg(ap, int); - ret = regmap_write(ssd130x->regmap, SSD13XX_COMMAND, value); - if (ret) - goto out_end; - } while (--count); - -out_end: - va_end(ap); - - return ret; -} - -/* - * Write a command byte sequence from a buffer. - * - * Like ssd130x_write_cmd() but takes a pre-built byte array instead of - * variadic arguments, handy when the command is already in an array or - * when the caller wants to use sizeof() for the length. + * Note that the ssd13xx protocol requires the opcode and each parameter to + * be written as a SSD13XX_COMMAND device register value. That is why a call + * to regmap_write(..., SSD13XX_COMMAND, ...) is done for each byte. */ static int ssd130x_write_cmds(struct ssd130x_device *ssd130x, const u8 *cmd, size_t len) @@ -310,6 +281,32 @@ static int ssd130x_write_cmds(struct ssd130x_device *ssd130x, const u8 *cmd, } /* + * Variadic wrapper around ssd130x_write_cmds(). The first variadic argument + * is the command opcode and the following are its parameters. + * + * The arguments are gathered into a fixed size buffer, so at most 8 bytes + * can be sent per call, i.e. an opcode and seven parameters. That covers + * every command this driver sends through it. Commands taking more parameters, + * such as the grey scale tables, must use ssd130x_write_cmds() instead. + */ +static int ssd130x_write_cmd(struct ssd130x_device *ssd130x, int count, + /* u8 cmd, u8 param, ... */...) +{ + u8 buf[8]; + va_list ap; + + if (drm_WARN_ON(&ssd130x->drm, count > sizeof(buf))) + return -EINVAL; + + va_start(ap, count); + for (int i = 0; i < count; i++) + buf[i] = va_arg(ap, int); + va_end(ap); + + return ssd130x_write_cmds(ssd130x, buf, count); +} + +/* * Run a packed command sequence. The format is a flat byte array where each * entry starts with a length byte followed by that many command bytes. A * zero length byte terminates the sequence. |
