Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp893157lqj; Mon, 3 Jun 2024 04:22:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUVkjcDI0RZS9q3b2HvmQ0tH04wdAWClbeiT0QvBS7anEqU0vGpPxcUZBLciEjaG7/i0bRr/Y5tB4uVX/8PdC1Ja00YONo1hSAl6aJGoQ== X-Google-Smtp-Source: AGHT+IFxLsBUO0GTG7Y44Bd+nVp8coWtMhc+YqdXnBV3GqrgmciUjm3kSu8iPgke5vbwW8rY6MWS X-Received: by 2002:ac8:5801:0:b0:43a:f80f:425b with SMTP id d75a77b69052e-43ff5288e25mr104918601cf.10.1717413748574; Mon, 03 Jun 2024 04:22:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717413748; cv=pass; d=google.com; s=arc-20160816; b=FljDX5C5a9rNRBANS0F8WXQNey07dy86q0SWxjKcLb5aJXntHsfUieYRgcU0wK1Im9 RlVJ7smiHRGyNaDnYCCtzEYDZjpTMBJNTo/p+wudxis4xbHJsoIPs1IlPRDOYpIAY73r OouOxqP0vtkwPvPq85Xjb4rb9zARWkg5NOa1/4//VMdCqeWuhQ3r98fa/k3jbInA1xMx JS5Ysqb5VMGc8EyD4QhFJmacKHE1mpHg40JpepbqESpp0lQ4HpMmPfAJcu8RnuXR/daI bxaoBcCmCm6p3a9OX8iDXhQshckbQNyx0rtzBqymhFgGTR/J4jGw4QZM5KBdap/Gi1CI PsSA== 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=3RoaNN29KZf3Grf/yJ1UzN+6ETj0sHmcYnQl5B9/hwc=; fh=Qca4uQclYGuGPeDwTz2ScN6SL0ZrdS/m01vAP+BwSac=; b=0Fd78KYB6mZqHUt4grdrxF0MOyY2SxzKItQzjsI/nun8byeuEA1QgVmJInSbVuc2RE G7UCg+eAQBTx495hMX0tGnFEfhObBjmF7NPPiP2zH14XKTNCMUwLzMNlcU0zWu5SHoHl mjD0PTp6zY86yfadST3dFlkHXF362ugqFLOS8WGLCQh84GNBbwJoCqAQ2+01p6g2UldS kDN/EI8qlzJY0TPhNT9/37S0Nr+wDY1k1lppa7H3XAqzeiY6brtbTj6GAX4bpdi0IcX5 bEgj22SBnI6mxloXgCbCSy5BLZv/4Tu/5b4x8PclPso/EoH4PrhKAWh9pyGD1iUdgDYe KnWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qe5V0Lgy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-199040-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199040-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-43ff23ac695si85987121cf.151.2024.06.03.04.22.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 04:22:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199040-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=qe5V0Lgy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-199040-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199040-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 416A61C21D29 for ; Mon, 3 Jun 2024 11:22:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3FD7C84E17; Mon, 3 Jun 2024 11:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qe5V0Lgy" 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 2739384A23; Mon, 3 Jun 2024 11:21:55 +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=1717413716; cv=none; b=q2NxYX08PawVVoGj9iwzUgCe7Z2Mlyq4U4u00zMObhNs0Vm5qdVft+jWXoHhhIeY9R0uDaGMezhAAXlZCr16WTLRilnBqxE6p+1OHC9O3g8eLQQr63w0Dbw7bQKwYyqKr2vZZ8oRBAXSL0+/FDfGkb2/bhSjxDskDrXSeAhYVbw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717413716; c=relaxed/simple; bh=Zkt7JT4UXzAYDHeuynIKtaz2NPxpWS4K+k2RFzjpOaI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=F4Hf5DRx/HwMetl20d+CxF/jQgV88v/1UcTbRmeA2THFr+2tStRFdyaXjw6BPMbinglP5oTG5tCQSnFr8ExnyZcMKYQw9HO1OJ66LwU6BCzxbljcn5g2sB/i0ugOYgMvfD1iytTSgHkouqnzV7OAt0k2FozCie4JBTrOQ1P13rE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qe5V0Lgy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id BB225C4AF10; Mon, 3 Jun 2024 11:21:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717413715; bh=Zkt7JT4UXzAYDHeuynIKtaz2NPxpWS4K+k2RFzjpOaI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=qe5V0LgyyQigVUp6f7OTXcQYYy+34R8qchi+rS2WpcIfADGzyc5EM/J1zYWhnKghH hcAAMupZ4nl3mixoRRLjEs9UDORJqNzMisVrKiOKAZFk2b1ZLQ6H3K85+YDEo3Nna4 LNvEw2LIHRJuwUj5vNBILw+J1hK0oJkS4ZkNE3Gv6iDP4APW/L0G/QGN0MTp+Hzz5l aUJHJUJab1UjzjdVEseNHvE845IZCvG+QWoK39s+zhH70VygBhdrjc/Nl7caS+l33w oxi5eAHAimIvWmTKOqgIWSbHuSp+JLmWNnXF56E5Xcwifst/xqukdzQ69LDeTAsYCW yhjPM6vYF8Drw== 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 B3627C25B75; Mon, 3 Jun 2024 11:21:55 +0000 (UTC) From: =?utf-8?q?Noralf_Tr=C3=B8nnes_via_B4_Relay?= Date: Mon, 03 Jun 2024 13:21:35 +0200 Subject: [PATCH v3 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: <20240603-panel-mipi-dbi-rgb666-v3-4-59ed53ca73da@tronnes.org> References: <20240603-panel-mipi-dbi-rgb666-v3-0-59ed53ca73da@tronnes.org> In-Reply-To: <20240603-panel-mipi-dbi-rgb666-v3-0-59ed53ca73da@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 , David Lechner 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=1717413714; l=5004; i=noralf@tronnes.org; s=20221122; h=from:subject:message-id; bh=NtI71S7qYFvJKxnnpF9sBqJW6UBDbKXW4W6XWCEPzEY=; b=/UU9GgDJ9YL9QphxZFmp1tSU8LpQy7IMUWbdVSQzfov3HnX//IFGl4Y8zlx8GQhRBHDjVBcmS AauvRxanc6TCfMwDqfiAEm7UXSq8r6b8+1GrZVbAEXh7Ep5kYx1X6Zh 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.1