drm/solomon: batch command sequences for SSD130x/132x/133x init
Subsystems (3)
cover drm/solomon: batch command sequences for SSD130x/132x/133x init
The ssd130x_init(), ssd132x_init(), and ssd133x_init() functions each issue long chains of individual ssd130x_write_cmd() calls, each followed by its own error check. This is verbose and makes the init sequences harder to read and maintain.
This series introduces ssd130x_run_cmd_seq(), which interprets a flat byte array of length-prefixed command entries terminated by a zero byte, and converts the three init functions to use it. The result is a net reduction of ~110 lines, with the hardware programming sequences now expressed as compact, declarative tables rather than imperative call-and-check chains.
---
Alberto Ruiz (4):
drm/solomon: add ssd130x_run_cmd_seq() for batch command execution
drm/solomon: use ssd130x_run_cmd_seq() in ssd130x_init()
drm/solomon: use ssd130x_run_cmd_seq() in ssd132x_init()
drm/solomon: use ssd130x_run_cmd_seq() in ssd133x_init()drivers/gpu/drm/solomon/ssd130x.c | 367 +++++++++++++------------------------- 1 file changed, 128 insertions(+), 239 deletions(-)
---
base-commit: 2b414a95b8f7307d42173ba9e580d6d3e2bcbfce
change-id: 20260612-ssd-batchcmd-35f7ba8c1e8b
Best regards,
Signature · 1 line
Alberto Ruiz <[email protected]>
PATCH 1/4 drm/solomon: add ssd130x_run_cmd_seq() for batch command execution
Introduce ssd130x_run_cmd_seq() that interprets a flat byte array of length-prefixed command entries terminated by a zero byte, removing the need for per-command error checking at each call site.
--- drivers/gpu/drm/solomon/ssd130x.c | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
drivers/gpu/drm/solomon/ssd130x.c +43 -0
@@ -276,6 +276,49 @@ static int ssd130x_write_cmd(struct ssd130x_device *ssd130x, int count,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. +*/ +static int ssd130x_write_cmds (struct ssd130x_device *ssd130x,const u8 *cmd, +size_t len) +{ +unsigned int i; +int ret; + +for (i =0 ; i < len; i++) { + ret =regmap_write (ssd130x->regmap,SSD13XX_COMMAND , cmd[i]); +if (ret) +return ret; + } + +return 0 ; +} + +/* +* 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. +* +* Example: { 2, 0x81, 0x80, 1, 0xAF, 0 } +* sends command {0x81, 0x80}, then command {0xAF}, then stops. +*/ +static int ssd130x_run_cmd_seq (struct ssd130x_device *ssd130x,const u8 *seq) +{ +while (*seq) { +u8 len = *seq++; +int ret =ssd130x_write_cmds (ssd130x, seq, len); + +if (ret) +return ret; + seq += len; + } + +return 0 ; +}/* Set address range for horizontal/vertical addressing modes */ static int ssd130x_set_col_range (struct ssd130x_device *ssd130x,u8 col_start,u8 cols)
Signature · 1 line
2.53.0
PATCH 2/4 drm/solomon: use ssd130x_run_cmd_seq() in ssd130x_init()
In reply to Alberto RuizReplace individual ssd130x_write_cmd() calls and per-command error checks with flat command arrays dispatched through ssd130x_run_cmd_seq().
--- drivers/gpu/drm/solomon/ssd130x.c | 72 ++++++++++++++------------------------- 1 file changed, 26 insertions(+), 46 deletions(-)
drivers/gpu/drm/solomon/ssd130x.c +26 -46
@@ -451,39 +451,25 @@ static int ssd130x_init(struct ssd130x_device *ssd130x)bool scan_mode;int ret; -/* Set initial contrast */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD13XX_CONTRAST , ssd130x->contrast); -if (ret <0 ) -return ret; - -/* Set segment re-map */ seg_remap = (SSD13XX_SET_SEG_REMAP | -SSD13XX_SET_SEG_REMAP_SET (ssd130x->seg_remap)); - ret =ssd130x_write_cmd (ssd130x,1 , seg_remap); -if (ret <0 ) -return ret; - -/* Set COM direction */ +SSD13XX_SET_SEG_REMAP_SET (ssd130x->seg_remap)); com_invdir = (SSD130X_SET_COM_SCAN_DIR | -SSD130X_SET_COM_SCAN_DIR_SET (ssd130x->com_invdir)); - ret =ssd130x_write_cmd (ssd130x,1 , com_invdir); -if (ret <0 ) -return ret; - -/* Set multiplex ratio value */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD13XX_SET_MULTIPLEX_RATIO , ssd130x->height -1 ); -if (ret <0 ) -return ret; - -/* set display offset value */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD130X_SET_DISPLAY_OFFSET , ssd130x->com_offset); -if (ret <0 ) -return ret; - -/* Set clock frequency */ +SSD130X_SET_COM_SCAN_DIR_SET (ssd130x->com_invdir)); dclk = (SSD130X_SET_CLOCK_DIV_SET (ssd130x->dclk_div -1 ) |SSD130X_SET_CLOCK_FREQ_SET (ssd130x->dclk_frq)); - ret =ssd130x_write_cmd (ssd130x,2 ,SSD130X_SET_CLOCK_FREQ , dclk); + +const u8 *cmds = (const u8 []) { +2 ,SSD13XX_CONTRAST , ssd130x->contrast, +/* Set segment re-map */ +1 , seg_remap, +/* Set COM scan direction */ +1 , com_invdir, +2 ,SSD13XX_SET_MULTIPLEX_RATIO , ssd130x->height -1 , +2 ,SSD130X_SET_DISPLAY_OFFSET , ssd130x->com_offset, +2 ,SSD130X_SET_CLOCK_FREQ , dclk, +0 , + }; + ret =ssd130x_run_cmd_seq (ssd130x, cmds);if (ret <0 )return ret;
@@ -505,36 +491,30 @@ static int ssd130x_init(struct ssd130x_device *ssd130x)/* Set precharge period in number of ticks from the internal clock */ precharge = (SSD130X_SET_PRECHARGE_PERIOD1_SET (ssd130x->prechargep1) |SSD130X_SET_PRECHARGE_PERIOD2_SET (ssd130x->prechargep2)); - ret =ssd130x_write_cmd (ssd130x,2 ,SSD130X_SET_PRECHARGE_PERIOD , precharge); -if (ret <0 ) -return ret; -/* Set COM pins configuration */ - compins =BIT (1 ); -/* +/* Set COM pins configuration +* * The COM scan mode field values are the inverse of the boolean DT * property "solomon,com-seq". The value 0b means scan from COM0 to * COM[N - 1] while 1b means scan from COM[N - 1] to COM0. */ scan_mode = !ssd130x->com_seq; - compins |= (SSD130X_SET_COM_PINS_CONFIG1_SET (scan_mode) | + compins =BIT (1 ) | (SSD130X_SET_COM_PINS_CONFIG1_SET (scan_mode) |SSD130X_SET_COM_PINS_CONFIG2_SET (ssd130x->com_lrremap)); - ret =ssd130x_write_cmd (ssd130x,2 ,SSD130X_SET_COM_PINS_CONFIG , compins); -if (ret <0 ) -return ret; - -/* Set VCOMH */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD130X_SET_VCOMH , ssd130x->vcomh); -if (ret <0 ) -return ret;/* Turn on the DC-DC Charge Pump */ chargepump =BIT (4 ); -if (ssd130x->device_info->need_chargepump) chargepump |=BIT (2 ); - ret =ssd130x_write_cmd (ssd130x,2 ,SSD130X_CHARGE_PUMP , chargepump); + cmds = (const u8 []) { +2 ,SSD130X_SET_PRECHARGE_PERIOD , precharge, +2 ,SSD130X_SET_COM_PINS_CONFIG , compins, +2 ,SSD130X_SET_VCOMH , ssd130x->vcomh, +2 ,SSD130X_CHARGE_PUMP , chargepump, +0 + }; + ret =ssd130x_run_cmd_seq (ssd130x, cmds);if (ret <0 )return ret;
Signature · 1 line
2.53.0
PATCH 3/4 drm/solomon: use ssd130x_run_cmd_seq() in ssd132x_init()
In reply to Alberto RuizReplace individual ssd130x_write_cmd() calls and per-command error checks with a flat command array dispatched through ssd130x_run_cmd_seq().
--- drivers/gpu/drm/solomon/ssd130x.c | 112 +++++++++----------------------------- 1 file changed, 27 insertions(+), 85 deletions(-)
drivers/gpu/drm/solomon/ssd130x.c +27 -85
@@ -551,92 +551,34 @@ static int ssd130x_init(struct ssd130x_device *ssd130x)static int ssd132x_init (struct ssd130x_device *ssd130x) { -int ret; - -/* Set initial contrast */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD13XX_CONTRAST ,0x80 ); -if (ret <0 ) -return ret; - -/* Set column start and end */ - ret =ssd130x_write_cmd (ssd130x,3 ,SSD132X_SET_COL_RANGE ,0x00 , - ssd130x->width /SSD132X_SEGMENT_WIDTH -1 ); -if (ret <0 ) -return ret; - -/* Set row start and end */ - ret =ssd130x_write_cmd (ssd130x,3 ,SSD132X_SET_ROW_RANGE ,0x00 , ssd130x->height -1 ); -if (ret <0 ) -return ret; -/* -* Horizontal Address Increment -* Re-map for Column Address, Nibble and COM -* COM Split Odd Even -*/ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD13XX_SET_SEG_REMAP ,0x53 ); -if (ret <0 ) -return ret; - -/* Set display start and offset */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD132X_SET_DISPLAY_START ,0x00 ); -if (ret <0 ) -return ret; - - ret =ssd130x_write_cmd (ssd130x,2 ,SSD132X_SET_DISPLAY_OFFSET ,0x00 ); -if (ret <0 ) -return ret; - -/* Set display mode normal */ - ret =ssd130x_write_cmd (ssd130x,1 ,SSD132X_SET_DISPLAY_NORMAL ); -if (ret <0 ) -return ret; - -/* Set multiplex ratio value */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD13XX_SET_MULTIPLEX_RATIO , ssd130x->height -1 ); -if (ret <0 ) -return ret; - -/* Set phase length */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD132X_SET_PHASE_LENGTH ,0x55 ); -if (ret <0 ) -return ret; - -/* Select default linear gray scale table */ - ret =ssd130x_write_cmd (ssd130x,1 ,SSD132X_SELECT_DEFAULT_TABLE ); -if (ret <0 ) -return ret; - -/* Set clock frequency */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD132X_SET_CLOCK_FREQ ,0x01 ); -if (ret <0 ) -return ret; - -/* Enable internal VDD regulator */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD132X_SET_FUNCTION_SELECT_A ,0x1 ); -if (ret <0 ) -return ret; - -/* Set pre-charge period */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD132X_SET_PRECHARGE_PERIOD ,0x01 ); -if (ret <0 ) -return ret; - -/* Set pre-charge voltage */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD132X_SET_PRECHARGE_VOLTAGE ,0x08 ); -if (ret <0 ) -return ret; - -/* Set VCOMH voltage */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD130X_SET_VCOMH_VOLTAGE ,0x07 ); -if (ret <0 ) -return ret; - -/* Enable second pre-charge and internal VSL */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD132X_SET_FUNCTION_SELECT_B ,0x62 ); -if (ret <0 ) -return ret; +const u8 cmds[] = { +2 ,SSD13XX_CONTRAST ,0x80 , +3 ,SSD132X_SET_COL_RANGE ,0x00 , + ssd130x->width /SSD132X_SEGMENT_WIDTH -1 , +3 ,SSD132X_SET_ROW_RANGE ,0x00 , ssd130x->height -1 , +/* +* Horizontal Address Increment +* Re-map for Column Address, Nibble and COM +* COM Split Odd Even +*/ +2 ,SSD13XX_SET_SEG_REMAP ,0x53 , +2 ,SSD132X_SET_DISPLAY_START ,0x00 , +2 ,SSD132X_SET_DISPLAY_OFFSET ,0x00 , +1 ,SSD132X_SET_DISPLAY_NORMAL , +2 ,SSD13XX_SET_MULTIPLEX_RATIO , ssd130x->height -1 , +2 ,SSD132X_SET_PHASE_LENGTH ,0x55 , +1 ,SSD132X_SELECT_DEFAULT_TABLE , +2 ,SSD132X_SET_CLOCK_FREQ ,0x01 , +2 ,SSD132X_SET_FUNCTION_SELECT_A ,0x1 , +2 ,SSD132X_SET_PRECHARGE_PERIOD ,0x01 , +2 ,SSD132X_SET_PRECHARGE_VOLTAGE ,0x08 , +2 ,SSD130X_SET_VCOMH_VOLTAGE ,0x07 , +/* Enable second pre-charge and internal VSL */ +2 ,SSD132X_SET_FUNCTION_SELECT_B ,0x62 , +0 , + }; -return 0 ; +return ssd130x_run_cmd_seq (ssd130x, cmds); }static int ssd133x_init (struct ssd130x_device *ssd130x)
Signature · 1 line
2.53.0
PATCH 4/4 drm/solomon: use ssd130x_run_cmd_seq() in ssd133x_init()
In reply to Alberto RuizReplace individual ssd130x_write_cmd() calls and per-command error checks with a flat command array dispatched through ssd130x_run_cmd_seq().
--- drivers/gpu/drm/solomon/ssd130x.c | 136 +++++++++----------------------------- 1 file changed, 30 insertions(+), 106 deletions(-)
drivers/gpu/drm/solomon/ssd130x.c +30 -106
@@ -583,113 +583,37 @@ static int ssd132x_init(struct ssd130x_device *ssd130x)static int ssd133x_init (struct ssd130x_device *ssd130x) { -int ret; - -/* Set color A contrast */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD133X_CONTRAST_A ,0x91 ); -if (ret <0 ) -return ret; - -/* Set color B contrast */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD133X_CONTRAST_B ,0x50 ); -if (ret <0 ) -return ret; - -/* Set color C contrast */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD133X_CONTRAST_C ,0x7d ); -if (ret <0 ) -return ret; - -/* Set master current */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD133X_SET_MASTER_CURRENT ,0x06 ); -if (ret <0 ) -return ret; - -/* Set column start and end */ - ret =ssd130x_write_cmd (ssd130x,3 ,SSD133X_SET_COL_RANGE ,0x00 , ssd130x->width -1 ); -if (ret <0 ) -return ret; - -/* Set row start and end */ - ret =ssd130x_write_cmd (ssd130x,3 ,SSD133X_SET_ROW_RANGE ,0x00 , ssd130x->height -1 ); -if (ret <0 ) -return ret; - -/* -* Horizontal Address Increment -* Normal order SA,SB,SC (e.g. RGB) -* COM Split Odd Even -* 256 color format -*/ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD13XX_SET_SEG_REMAP ,0x20 ); -if (ret <0 ) -return ret; - -/* Set display start and offset */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD133X_SET_DISPLAY_START ,0x00 ); -if (ret <0 ) -return ret; - - ret =ssd130x_write_cmd (ssd130x,2 ,SSD133X_SET_DISPLAY_OFFSET ,0x00 ); -if (ret <0 ) -return ret; - -/* Set display mode normal */ - ret =ssd130x_write_cmd (ssd130x,1 ,SSD133X_SET_DISPLAY_NORMAL ); -if (ret <0 ) -return ret; - -/* Set multiplex ratio value */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD13XX_SET_MULTIPLEX_RATIO , ssd130x->height -1 ); -if (ret <0 ) -return ret; - -/* Set master configuration */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD133X_SET_MASTER_CONFIG ,0x8e ); -if (ret <0 ) -return ret; - -/* Set power mode */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD133X_POWER_SAVE_MODE ,0x0b ); -if (ret <0 ) -return ret; - -/* Set Phase 1 and 2 period */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD133X_PHASES_PERIOD ,0x31 ); -if (ret <0 ) -return ret; - -/* Set clock divider */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD133X_SET_CLOCK_FREQ ,0xf0 ); -if (ret <0 ) -return ret; - -/* Set pre-charge A */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD132X_SET_PRECHARGE_A ,0x64 ); -if (ret <0 ) -return ret; - -/* Set pre-charge B */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD132X_SET_PRECHARGE_B ,0x78 ); -if (ret <0 ) -return ret; - -/* Set pre-charge C */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD132X_SET_PRECHARGE_C ,0x64 ); -if (ret <0 ) -return ret; - -/* Set pre-charge level */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD133X_SET_PRECHARGE_VOLTAGE ,0x3a ); -if (ret <0 ) -return ret; - -/* Set VCOMH voltage */ - ret =ssd130x_write_cmd (ssd130x,2 ,SSD133X_SET_VCOMH_VOLTAGE ,0x3e ); -if (ret <0 ) -return ret; +const u8 cmds[] = { +2 ,SSD133X_CONTRAST_A ,0x91 , +2 ,SSD133X_CONTRAST_B ,0x50 , +2 ,SSD133X_CONTRAST_C ,0x7d , +2 ,SSD133X_SET_MASTER_CURRENT ,0x06 , +3 ,SSD133X_SET_COL_RANGE ,0x00 , ssd130x->width -1 , +3 ,SSD133X_SET_ROW_RANGE ,0x00 , ssd130x->height -1 , +/* +* Horizontal Address Increment +* Normal order SA,SB,SC (e.g. RGB) +* COM Split Odd Even +* 256 color format +*/ +2 ,SSD13XX_SET_SEG_REMAP ,0x20 , +2 ,SSD133X_SET_DISPLAY_START ,0x00 , +2 ,SSD133X_SET_DISPLAY_OFFSET ,0x00 , +1 ,SSD133X_SET_DISPLAY_NORMAL , +2 ,SSD13XX_SET_MULTIPLEX_RATIO , ssd130x->height -1 , +2 ,SSD133X_SET_MASTER_CONFIG ,0x8e , +2 ,SSD133X_POWER_SAVE_MODE ,0x0b , +2 ,SSD133X_PHASES_PERIOD ,0x31 , +2 ,SSD133X_SET_CLOCK_FREQ ,0xf0 , +2 ,SSD132X_SET_PRECHARGE_A ,0x64 , +2 ,SSD132X_SET_PRECHARGE_B ,0x78 , +2 ,SSD132X_SET_PRECHARGE_C ,0x64 , +2 ,SSD133X_SET_PRECHARGE_VOLTAGE ,0x3a , +2 ,SSD133X_SET_VCOMH_VOLTAGE ,0x3e , +0 , + }; -return 0 ; +return ssd130x_run_cmd_seq (ssd130x, cmds); } static int ssd130x_update_rect(struct ssd130x_device *ssd130x,
Signature · 1 line
2.53.0
Alberto Ruiz via B4 Relay <[email protected]> writes:
Hello Alberto,
Thanks for the patches. Nice cleanup!
Quoted 12 lines
The
ssd130x_init(),ssd132x_init(), andssd133x_init()functions each issue long chains of individualssd130x_write_cmd()calls, each followed by its own error check. This is verbose and makes the init sequences harder to read and maintain.This series introduces
ssd130x_run_cmd_seq(), which interprets a flat byte array of length-prefixed command entries terminated by a zero byte, and converts the three init functions to use it. The result is a net reduction of ~110 lines, with the hardware programming sequences now expressed as compact, declarative tables rather than imperative call-and-check chains.
Quoted 7 lines
Signed-off-by Alberto Ruiz <[email protected]>---
Alberto Ruiz (4):drm/solomon: add ssd130x_run_cmd_seq() for batch command execution drm/solomon: use ssd130x_run_cmd_seq() in ssd130x_init() drm/solomon: use ssd130x_run_cmd_seq() in ssd132x_init() drm/solomon: use ssd130x_run_cmd_seq() in ssd133x_init()
For all the patches:
I'll wait for a few days to merge them, in case someone else have comments.
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Quoted 26 lines · Javier Martinez Canillas
Alberto Ruiz via B4 Relay <[email protected]> writes:
Hello Alberto,
Thanks for the patches. Nice cleanup!
Quoted 12 lines
The
ssd130x_init(),ssd132x_init(), andssd133x_init()functions each issue long chains of individualssd130x_write_cmd()calls, each followed by its own error check. This is verbose and makes the init sequences harder to read and maintain.This series introduces
ssd130x_run_cmd_seq(), which interprets a flat byte array of length-prefixed command entries terminated by a zero byte, and converts the three init functions to use it. The result is a net reduction of ~110 lines, with the hardware programming sequences now expressed as compact, declarative tables rather than imperative call-and-check chains.Quoted 7 lines
Signed-off-by Alberto Ruiz <[email protected]>---
Alberto Ruiz (4):drm/solomon: add ssd130x_run_cmd_seq() for batch command execution drm/solomon: use ssd130x_run_cmd_seq() in ssd130x_init() drm/solomon: use ssd130x_run_cmd_seq() in ssd132x_init() drm/solomon: use ssd130x_run_cmd_seq() in ssd133x_init()
Quoted 7 lines
For all the patches:
Reviewed-by Javier Martinez Canillas <[email protected]>I'll wait for a few days to merge them, in case someone else have comments.
Pushed to drm-misc (drm-misc-next). Thanks!
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat