Skip to content

Commit 4aebb79

Browse files
committed
drm/mipi-dbi: Add support for DRM_FORMAT_RGB888
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. v4: - s/emulation_format/pixel_format/ (Dmitry) Reviewed-by: Dmitry Baryshkov <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Noralf Trønnes <[email protected]>
1 parent df3fb27 commit 4aebb79

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

drivers/gpu/drm/drm_mipi_dbi.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ int mipi_dbi_buf_copy(void *dst, struct iosys_map *src, struct drm_framebuffer *
206206
struct drm_rect *clip, bool swap,
207207
struct drm_format_conv_state *fmtcnv_state)
208208
{
209+
struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev);
209210
struct drm_gem_object *gem = drm_gem_fb_get_obj(fb, 0);
210211
struct iosys_map dst_map = IOSYS_MAP_INIT_VADDR(dst);
211212
int ret;
@@ -222,8 +223,18 @@ int mipi_dbi_buf_copy(void *dst, struct iosys_map *src, struct drm_framebuffer *
222223
else
223224
drm_fb_memcpy(&dst_map, NULL, src, fb, clip);
224225
break;
226+
case DRM_FORMAT_RGB888:
227+
drm_fb_memcpy(&dst_map, NULL, src, fb, clip);
228+
break;
225229
case DRM_FORMAT_XRGB8888:
226-
drm_fb_xrgb8888_to_rgb565(&dst_map, NULL, src, fb, clip, fmtcnv_state, swap);
230+
switch (dbidev->pixel_format) {
231+
case DRM_FORMAT_RGB565:
232+
drm_fb_xrgb8888_to_rgb565(&dst_map, NULL, src, fb, clip, fmtcnv_state, swap);
233+
break;
234+
case DRM_FORMAT_RGB888:
235+
drm_fb_xrgb8888_to_rgb888(&dst_map, NULL, src, fb, clip, fmtcnv_state);
236+
break;
237+
}
227238
break;
228239
default:
229240
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,
260271
struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev);
261272
unsigned int height = rect->y2 - rect->y1;
262273
unsigned int width = rect->x2 - rect->x1;
274+
const struct drm_format_info *dst_format;
263275
struct mipi_dbi *dbi = &dbidev->dbi;
264276
bool swap = dbi->swap_bytes;
265277
int ret = 0;
278+
size_t len;
266279
bool full;
267280
void *tr;
268281

@@ -283,8 +296,13 @@ static void mipi_dbi_fb_dirty(struct iosys_map *src, struct drm_framebuffer *fb,
283296
mipi_dbi_set_window_address(dbidev, rect->x1, rect->x2 - 1, rect->y1,
284297
rect->y2 - 1);
285298

286-
ret = mipi_dbi_command_buf(dbi, MIPI_DCS_WRITE_MEMORY_START, tr,
287-
width * height * 2);
299+
if (fb->format->format == DRM_FORMAT_XRGB8888)
300+
dst_format = drm_format_info(dbidev->pixel_format);
301+
else
302+
dst_format = fb->format;
303+
len = drm_format_info_min_pitch(dst_format, 0, width) * height;
304+
305+
ret = mipi_dbi_command_buf(dbi, MIPI_DCS_WRITE_MEMORY_START, tr, len);
288306
err_msg:
289307
if (ret)
290308
drm_err_once(fb->dev, "Failed to update display %d\n", ret);
@@ -572,7 +590,7 @@ static const uint32_t mipi_dbi_formats[] = {
572590
* has one fixed &drm_display_mode which is rotated according to @rotation.
573591
* This mode is used to set the mode config min/max width/height properties.
574592
*
575-
* Use mipi_dbi_dev_init() if you don't need custom formats.
593+
* Use mipi_dbi_dev_init() if you want native RGB565 and emulated XRGB8888 format.
576594
*
577595
* Note:
578596
* 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,
631649
drm->mode_config.min_height = dbidev->mode.vdisplay;
632650
drm->mode_config.max_height = dbidev->mode.vdisplay;
633651
dbidev->rotation = rotation;
652+
dbidev->pixel_format = formats[0];
653+
if (formats[0] == DRM_FORMAT_RGB888)
654+
dbidev->dbi.write_memory_bpw = 8;
634655

635656
DRM_DEBUG_KMS("rotation = %u\n", rotation);
636657

include/drm/drm_mipi_dbi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ struct mipi_dbi_dev {
101101
*/
102102
struct drm_display_mode mode;
103103

104+
/**
105+
* @pixel_format: Native pixel format (DRM_FORMAT\_\*)
106+
*/
107+
u32 pixel_format;
108+
104109
/**
105110
* @tx_buf: Buffer used for transfer (copy clip rect area)
106111
*/

0 commit comments

Comments
 (0)