From 2f1ac69c0693a42a6d0026744e02df6275e3a169 Mon Sep 17 00:00:00 2001 From: Amit Barzilai Date: Mon, 22 Jun 2026 15:26:03 +0300 Subject: [PATCH] drm/ssd130x: hoist column and row addresses out of repeated division The ssd132x_update_rect had to calculate the column address twice in the same function by dividing the byte address and the segment_width. Optimize this by hoisting the result into a col variable. Renamed the "y" variable to "row" to match the change made in the x axis. Signed-off-by: Amit Barzilai Reviewed-by: Javier Martinez Canillas Link: https://patch.msgid.link/20260622122604.32500-3-amit.barzilai22@gmail.com Signed-off-by: Javier Martinez Canillas --- drivers/gpu/drm/solomon/ssd130x.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ssd130x.c index 653c6d691b64..753aad54332f 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -725,9 +725,9 @@ static int ssd132x_update_rect(struct ssd130x_device *ssd130x, struct drm_rect *rect, u8 *buf, u8 *data_array) { - unsigned int x = rect->x1; - unsigned int y = rect->y1; unsigned int segment_width = SSD132X_SEGMENT_WIDTH; + unsigned int col = rect->x1 / segment_width; + unsigned int row = rect->y1; unsigned int width = drm_rect_width(rect); unsigned int height = drm_rect_height(rect); unsigned int columns = DIV_ROUND_UP(width, segment_width); @@ -737,7 +737,7 @@ static int ssd132x_update_rect(struct ssd130x_device *ssd130x, unsigned int i, j; int ret; - drm_WARN_ONCE(drm, x % segment_width != 0, "x must be aligned to screen segment\n"); + drm_WARN_ONCE(drm, rect->x1 % segment_width != 0, "x must be aligned to screen segment\n"); /* * The screen is divided in Segment and Common outputs, where @@ -754,13 +754,12 @@ static int ssd132x_update_rect(struct ssd130x_device *ssd130x, */ /* Set column start and end */ - ret = ssd130x_write_cmd(ssd130x, 3, SSD132X_SET_COL_RANGE, x / segment_width, - x / segment_width + columns - 1); + ret = ssd130x_write_cmd(ssd130x, 3, SSD132X_SET_COL_RANGE, col, col + columns - 1); if (ret < 0) return ret; /* Set row start and end */ - ret = ssd130x_write_cmd(ssd130x, 3, SSD132X_SET_ROW_RANGE, y, y + rows - 1); + ret = ssd130x_write_cmd(ssd130x, 3, SSD132X_SET_ROW_RANGE, row, row + rows - 1); if (ret < 0) return ret;