From nobody Sun Feb 8 21:11:41 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8531EB64DD for ; Thu, 13 Jul 2023 13:18:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235165AbjGMNR7 (ORCPT ); Thu, 13 Jul 2023 09:17:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234817AbjGMNRb (ORCPT ); Thu, 13 Jul 2023 09:17:31 -0400 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19DA1270B for ; Thu, 13 Jul 2023 06:17:25 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6264:77e5:42e2:477d]) by laurent.telenet-ops.be with bizsmtp id LdHN2A00U3wy6xv01dHNpb; Thu, 13 Jul 2023 15:17:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qJwC3-001Gqw-2D; Thu, 13 Jul 2023 15:17:22 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1qJwCA-00GWyh-OV; Thu, 13 Jul 2023 15:17:22 +0200 From: Geert Uytterhoeven To: Javier Martinez Canillas , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 4/8] drm/ssd130x: Add support for DRM_FORMAT_R1 Date: Thu, 13 Jul 2023 15:17:12 +0200 Message-Id: <72746f6d9c47f09fc057ad7a4bbb3b7f423af803.1689252746.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The native display format is monochrome light-on-dark (R1). Hence add support for R1, so monochrome applications can avoid the overhead of back-and-forth conversions between R1 and XR24. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas --- This work interfered with commit 49d7d581ceaf4cf8 ("drm/ssd130x: Don't allocate buffers on each plane update") in drm-misc/for-linux-next, which always allocates the buffer upfront, while it is no longer needed when never using XR24. Probably ssd130x->buffer should be allocated on first use. And why not allocate the buffers using devm_kcalloc()? --- drivers/gpu/drm/solomon/ssd130x.c | 57 ++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ss= d130x.c index 8ef5f61854fd7340..130e33a1ba3cba00 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -466,15 +466,14 @@ static int ssd130x_init(struct ssd130x_device *ssd130= x) SSD130X_SET_ADDRESS_MODE_HORIZONTAL); } =20 -static int ssd130x_update_rect(struct ssd130x_device *ssd130x, struct drm_= rect *rect) +static int ssd130x_update_rect(struct ssd130x_device *ssd130x, u8 *buf, + unsigned int pitch, struct drm_rect *rect) { unsigned int x =3D rect->x1; unsigned int y =3D rect->y1; - u8 *buf =3D ssd130x->buffer; u8 *data_array =3D ssd130x->data_array; unsigned int width =3D drm_rect_width(rect); unsigned int height =3D drm_rect_height(rect); - unsigned int line_length =3D DIV_ROUND_UP(width, 8); unsigned int page_height =3D ssd130x->device_info->page_height; unsigned int pages =3D DIV_ROUND_UP(height, page_height); struct drm_device *drm =3D &ssd130x->drm; @@ -534,7 +533,7 @@ if (!data_array) { pr_info("%s: data_array not yet init= ialized\n", __func__); re u8 data =3D 0; =20 for (k =3D 0; k < m; k++) { - u8 byte =3D buf[(8 * i + k) * line_length + j / 8]; + u8 byte =3D buf[(8 * i + k) * pitch + j / 8]; u8 bit =3D (byte >> (j % 8)) & 1; =20 data |=3D bit << k; @@ -570,6 +569,8 @@ if (!data_array) { pr_info("%s: data_array not yet init= ialized\n", __func__); re =20 static void ssd130x_clear_screen(struct ssd130x_device *ssd130x) { + unsigned int pitch =3D DIV_ROUND_UP(ssd130x->width, 8); + u8 *buf =3D ssd130x->buffer; struct drm_rect fullscreen =3D { .x1 =3D 0, .x2 =3D ssd130x->width, @@ -577,7 +578,7 @@ static void ssd130x_clear_screen(struct ssd130x_device = *ssd130x) .y2 =3D ssd130x->height, }; =20 - ssd130x_update_rect(ssd130x, &fullscreen); + ssd130x_update_rect(ssd130x, buf, pitch, &fullscreen); } =20 static int ssd130x_fb_blit_rect(struct drm_framebuffer *fb, const struct i= osys_map *vmap, @@ -588,27 +589,48 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffe= r *fb, const struct iosys_m struct iosys_map dst; unsigned int dst_pitch; int ret =3D 0; - u8 *buf =3D ssd130x->buffer; - - if (!buf) - return 0; + u8 *buf; =20 /* Align y to display page boundaries */ rect->y1 =3D round_down(rect->y1, page_height); rect->y2 =3D min_t(unsigned int, round_up(rect->y2, page_height), ssd130x= ->height); =20 - dst_pitch =3D DIV_ROUND_UP(drm_rect_width(rect), 8); + switch (fb->format->format) { + case DRM_FORMAT_R1: + /* Align x to byte boundaries */ + rect->x1 =3D round_down(rect->x1, 8); + rect->x2 =3D round_up(rect->x2, 8); =20 - ret =3D drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); - if (ret) - return ret; + ret =3D drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); + if (ret) + return ret; =20 - iosys_map_set_vaddr(&dst, buf); - drm_fb_xrgb8888_to_mono(&dst, &dst_pitch, vmap, fb, rect); + dst_pitch =3D fb->pitches[0]; + buf =3D vmap[0].vaddr + rect->y1 * dst_pitch + rect->x1 / 8; =20 - drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); + ssd130x_update_rect(ssd130x, buf, dst_pitch, rect); =20 - ssd130x_update_rect(ssd130x, rect); + drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); + break; + + case DRM_FORMAT_XRGB8888: + dst_pitch =3D DIV_ROUND_UP(drm_rect_width(rect), 8); + buf =3D ssd130x->buffer; + if (!buf) + return 0; + + ret =3D drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); + if (ret) + return ret; + + iosys_map_set_vaddr(&dst, buf); + drm_fb_xrgb8888_to_mono(&dst, &dst_pitch, vmap, fb, rect); + + drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); + + ssd130x_update_rect(ssd130x, buf, dst_pitch, rect); + break; + } =20 return ret; } @@ -797,6 +819,7 @@ static const struct drm_mode_config_funcs ssd130x_mode_= config_funcs =3D { }; =20 static const uint32_t ssd130x_formats[] =3D { + DRM_FORMAT_R1, DRM_FORMAT_XRGB8888, }; =20 --=20 2.34.1