Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1576658lqo; Sun, 12 May 2024 08:27:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVzP5iRty4Ws+vrxNFEsGQmC4WdbmcHX3De3EHxItCo0f1GSIIhnTx5QX0rZYuOh1huI4jcP+73LyXhSJRzM9STJKfTRXaOWMY7b/rH2w== X-Google-Smtp-Source: AGHT+IFjd6frX8GOWCx5QbRkaRN+fX5HvE30mAH0jsCnQMDTZvLB1/rfN0p0eytFwY6PfvmscTFY X-Received: by 2002:a05:6e02:1fcf:b0:369:940b:2cd4 with SMTP id e9e14a558f8ab-36cc14760c3mr99280315ab.5.1715527622085; Sun, 12 May 2024 08:27:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715527622; cv=pass; d=google.com; s=arc-20160816; b=IWIl4TbZvlOrF6JZiO7gwich1nlhLm8bdkqKOegjYxO8Kf7NhigmRfwnx6Ur53Tz/S tsgcT36jsQeokz/VZE++MnvADWVv/Uwg6xby5V5c00qlwUDAHMDw3ovvqFGuEBMiRHKh NlQa4KE2HlRW9k6S/iOzftXelp3js741dBYx0u4f94uQFbr+UbV6P/XA1XYBUjetLOkz Z5Iy1uKSFM1mBfXmbvQ9IfeXXl8nshPjCwZ4sOVIq5yTMr6+6oLfyVXrD7QC6wd/Flus 4DpzJyhzhaQe8ZKQaBxNufSZXfTK0ykIAohqQbz83LaMmgF/Ffk1D7TkseY2+/gBV76c opWA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:date:from:dkim-signature; bh=zN/WcLWD6w9V7RSjj1B8bHhSuoWFfh+CZvXGbu0wRKU=; fh=csJvTvirFA4Yxnuv/QwMDA7kEl0DEbvIwTx+VYJVsSc=; b=K8lF5+/nWg1ZZuanJVXaWxFTMh2z+vo/vbLyES9zovQtUrubidfBVUkOPzeiPmkDCX JMOuohuTwpl8TDmNqceEsVV7jLyCVxK8njYhnqJPdtNigRAxw1PiY0LTpOwqekjfBmmc aNJocM6hSXMlP50PJZnAZPORqZPqaWxQZv28xtDhEY8UARoIOZlPMFhuFSpeo9q8kusM X4BXxicKxzVSN+CJ6b6+zPf6FbCOrNjEyKDWEFu1mhaIKIhW6uCLM1P7bwOVsBGSpMao Er0oRWPbZIv9aSZKhD+5SSjad6H4zsTbwxtvv3583tiAk338DKaVk/n/jyUGjoMzXqMm 5Wdw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s5tlIij+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-176921-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176921-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43df5670c77si79388661cf.287.2024.05.12.08.27.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 May 2024 08:27:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176921-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s5tlIij+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-176921-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176921-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B9C2A1C203AB for ; Sun, 12 May 2024 15:27:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED2EE52F71; Sun, 12 May 2024 15:25:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s5tlIij+" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2A2740879; Sun, 12 May 2024 15:25:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715527547; cv=none; b=OYEoH0cddImmHgl5YS5dfXP7LgyqPJPr1nFseO4zOdSQqFPBf2nuVOfViI5AvbE+mDfBPV+lIfkJZSXNSXhbx94txRmSWqirja37xo6r9Rqzaq2Sg4lyAlLPezS3r7oxlDpLL4CNvlFIslLowYqk3nOuzkQvyExjJ7Mp0NR8AQg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715527547; c=relaxed/simple; bh=3dqNGvZkC+MMnGTynjmV0t4nfsy//bK88jV+fDke0Aw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=icbhWa7PqmHAJczYY8L02iA+wf5MZuuZ0ZGxe8lXYdGOYI3y9uBMCMmxWRrqpiK3UCL50+Qr9f96ov80prZ+g1bL7Ax1z8GfEYehI2DXvRJMc99CP65jDB5HO1MKeSqls15duleyMhOzk3WqqRv/ZLh+3D5/n3Nrbxo/7iv1Zbk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s5tlIij+; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id 3B51DC32786; Sun, 12 May 2024 15:25:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715527547; bh=3dqNGvZkC+MMnGTynjmV0t4nfsy//bK88jV+fDke0Aw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=s5tlIij+stR1JggmcdjH85syZjmv6GX+Dt3VoKABm/JbSU2pGQCaWIKrT+ddcdDwQ 9jS4vfTciYjB+sFfJIzOhxc7ampxvbZL00hdvfn6pMp0y1oq1wWbCRc1axGR6zDxnG GopK/fTxa2ERhaLHUxIACMEV4fimNYdn+LZE8NxWa2zZXhTaF+A4zeAc24xFmoxkJJ zk5i9Xj9GrKfhLxtxym5IhmAqcpKQILUIbNbbAl2ZScc5BTOnw2EYeT1Psoy6+o/GZ o6dsJtSMH898tkXbYCsDN8M2Xw44xTHRRNSxKOyopYkgUyfvVfH6b9n3wpHhlL0hrQ QvgCEOM+ladlA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31DB7C25B4F; Sun, 12 May 2024 15:25:47 +0000 (UTC) From: =?utf-8?q?Noralf_Tr=C3=B8nnes_via_B4_Relay?= Date: Sun, 12 May 2024 17:25:41 +0200 Subject: [PATCH v2 4/5] drm/mipi-dbi: Add support for DRM_FORMAT_RGB888 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240512-panel-mipi-dbi-rgb666-v2-4-49dd266328a0@tronnes.org> References: <20240512-panel-mipi-dbi-rgb666-v2-0-49dd266328a0@tronnes.org> In-Reply-To: <20240512-panel-mipi-dbi-rgb666-v2-0-49dd266328a0@tronnes.org> To: Neil Armstrong , Jessica Zhang , Sam Ravnborg , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Kamlesh Gurudasani , Tommaso Merciai , =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715527545; l=5004; i=noralf@tronnes.org; s=20221122; h=from:subject:message-id; bh=W6oL0rQmok4cxorsnLB3NONNFaDQoJFHpq/k5uI9z9M=; b=W40wPFxyCV22GVgWBzzdUAm6PP694Wn3d2OAV9DFwWt6ksL0Wxnpacxv7FSOuEs/ibZ2f9AIq mAlCIniAkkKBtsL1hj0CG6fGVbqfNy4WIk6DEcJMdW6tTf6J4021ypQ X-Developer-Key: i=noralf@tronnes.org; a=ed25519; pk=0o9is4iddvvlrY3yON5SVtAbgPnVs0LfQsjfqR2Hvz8= X-Endpoint-Received: by B4 Relay for noralf@tronnes.org/20221122 with auth_id=8 X-Original-From: =?utf-8?q?Noralf_Tr=C3=B8nnes?= Reply-To: noralf@tronnes.org From: Noralf Trønnes DRM_FORMAT_RGB888 is 24 bits per pixel and it would be natural to send it on the SPI bus using a 24 bits per word transfer. The problem with this is that not all SPI controllers support 24 bpw. Since DRM_FORMAT_RGB888 is stored in memory as little endian and the SPI bus is big endian we use 8 bpw to always get the same pixel format on the bus: b8g8r8. The MIPI DCS specification lists the standard commands that can be sent over the MIPI DBI interface. The set_address_mode (36h) command has one bit in the parameter that controls RGB/BGR order. This means that the controller can be configured to receive the pixel as BGR. RGB888 is rarely supported on these controllers but RGB666 is very common. All datasheets I have seen do at least support the pixel format option where each color is sent as one byte and the 6 MSB's are used. All this put together means that we can send each pixel as b8g8r8 and an RGB666 capable controller sees this as b6x2g6x2r6x2. Signed-off-by: Noralf Trønnes --- drivers/gpu/drm/drm_mipi_dbi.c | 29 +++++++++++++++++++++++++---- include/drm/drm_mipi_dbi.h | 5 +++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_mipi_dbi.c b/drivers/gpu/drm/drm_mipi_dbi.c index 77f8a828d6e0..eb330676857c 100644 --- a/drivers/gpu/drm/drm_mipi_dbi.c +++ b/drivers/gpu/drm/drm_mipi_dbi.c @@ -206,6 +206,7 @@ int mipi_dbi_buf_copy(void *dst, struct iosys_map *src, struct drm_framebuffer * struct drm_rect *clip, bool swap, struct drm_format_conv_state *fmtcnv_state) { + struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev); struct drm_gem_object *gem = drm_gem_fb_get_obj(fb, 0); struct iosys_map dst_map = IOSYS_MAP_INIT_VADDR(dst); int ret; @@ -222,8 +223,18 @@ int mipi_dbi_buf_copy(void *dst, struct iosys_map *src, struct drm_framebuffer * else drm_fb_memcpy(&dst_map, NULL, src, fb, clip); break; + case DRM_FORMAT_RGB888: + drm_fb_memcpy(&dst_map, NULL, src, fb, clip); + break; case DRM_FORMAT_XRGB8888: - drm_fb_xrgb8888_to_rgb565(&dst_map, NULL, src, fb, clip, fmtcnv_state, swap); + switch (dbidev->emulation_format) { + case DRM_FORMAT_RGB565: + drm_fb_xrgb8888_to_rgb565(&dst_map, NULL, src, fb, clip, fmtcnv_state, swap); + break; + case DRM_FORMAT_RGB888: + drm_fb_xrgb8888_to_rgb888(&dst_map, NULL, src, fb, clip, fmtcnv_state); + break; + } break; default: drm_err_once(fb->dev, "Format is not supported: %p4cc\n", @@ -260,9 +271,11 @@ static void mipi_dbi_fb_dirty(struct iosys_map *src, struct drm_framebuffer *fb, struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev); unsigned int height = rect->y2 - rect->y1; unsigned int width = rect->x2 - rect->x1; + const struct drm_format_info *dst_format; struct mipi_dbi *dbi = &dbidev->dbi; bool swap = dbi->swap_bytes; int ret = 0; + size_t len; bool full; void *tr; @@ -283,8 +296,13 @@ static void mipi_dbi_fb_dirty(struct iosys_map *src, struct drm_framebuffer *fb, mipi_dbi_set_window_address(dbidev, rect->x1, rect->x2 - 1, rect->y1, rect->y2 - 1); - ret = mipi_dbi_command_buf(dbi, MIPI_DCS_WRITE_MEMORY_START, tr, - width * height * 2); + if (fb->format->format == DRM_FORMAT_XRGB8888) + dst_format = drm_format_info(dbidev->emulation_format); + else + dst_format = fb->format; + len = drm_format_info_min_pitch(dst_format, 0, width) * height; + + ret = mipi_dbi_command_buf(dbi, MIPI_DCS_WRITE_MEMORY_START, tr, len); err_msg: if (ret) drm_err_once(fb->dev, "Failed to update display %d\n", ret); @@ -572,7 +590,7 @@ static const uint32_t mipi_dbi_formats[] = { * has one fixed &drm_display_mode which is rotated according to @rotation. * This mode is used to set the mode config min/max width/height properties. * - * Use mipi_dbi_dev_init() if you don't need custom formats. + * Use mipi_dbi_dev_init() if you want native RGB565 and emulated XRGB8888 format. * * Note: * Some of the helper functions expects RGB565 to be the default format and the @@ -631,6 +649,9 @@ int mipi_dbi_dev_init_with_formats(struct mipi_dbi_dev *dbidev, drm->mode_config.min_height = dbidev->mode.vdisplay; drm->mode_config.max_height = dbidev->mode.vdisplay; dbidev->rotation = rotation; + dbidev->emulation_format = formats[0]; + if (formats[0] == DRM_FORMAT_RGB888) + dbidev->dbi.write_memory_bpw = 8; DRM_DEBUG_KMS("rotation = %u\n", rotation); diff --git a/include/drm/drm_mipi_dbi.h b/include/drm/drm_mipi_dbi.h index b36596efdcc3..85bf19b98cee 100644 --- a/include/drm/drm_mipi_dbi.h +++ b/include/drm/drm_mipi_dbi.h @@ -101,6 +101,11 @@ struct mipi_dbi_dev { */ struct drm_display_mode mode; + /** + * @emulation_format: Pixel format to use when emulating XRGB8888 + */ + u32 emulation_format; + /** * @tx_buf: Buffer used for transfer (copy clip rect area) */ -- 2.45.0