Skip to content

Commit aa61186

Browse files
committed
drm/tiny: panel-mipi-dbi: Support the pixel format property
Add support for these pixel format property values: - r5g6b5, RGB565 - b6x2g6x2r6x2, BGR666 BGR666 is presented to userspace as RGB888. The 2 LSB in each color are discarded by the controller. The pixel is sent on the wire using 8 bits per word (little endian) so the controller sees it as BGR. RGB565 is the default if the property is not present. Reviewed-by: Neil Armstrong <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Noralf Trønnes <[email protected]>
1 parent 4aebb79 commit aa61186

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

drivers/gpu/drm/tiny/panel-mipi-dbi.c

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,49 @@
2626

2727
#include <video/mipi_display.h>
2828

29+
struct panel_mipi_dbi_format {
30+
const char *name;
31+
u32 fourcc;
32+
unsigned int bpp;
33+
};
34+
35+
static const struct panel_mipi_dbi_format panel_mipi_dbi_formats[] = {
36+
{ "r5g6b5", DRM_FORMAT_RGB565, 16 },
37+
{ "b6x2g6x2r6x2", DRM_FORMAT_RGB888, 24 },
38+
};
39+
40+
static int panel_mipi_dbi_get_format(struct device *dev, u32 *formats, unsigned int *bpp)
41+
{
42+
const char *format_name;
43+
unsigned int i;
44+
int ret;
45+
46+
formats[1] = DRM_FORMAT_XRGB8888;
47+
48+
ret = device_property_read_string(dev, "format", &format_name);
49+
if (ret) {
50+
/* Old Device Trees don't have this property */
51+
formats[0] = DRM_FORMAT_RGB565;
52+
*bpp = 16;
53+
return 0;
54+
}
55+
56+
for (i = 0; i < ARRAY_SIZE(panel_mipi_dbi_formats); i++) {
57+
const struct panel_mipi_dbi_format *format = &panel_mipi_dbi_formats[i];
58+
59+
if (strcmp(format_name, format->name))
60+
continue;
61+
62+
formats[0] = format->fourcc;
63+
*bpp = format->bpp;
64+
return 0;
65+
}
66+
67+
dev_err(dev, "Pixel format is not supported: '%s'\n", format_name);
68+
69+
return -EINVAL;
70+
}
71+
2972
static const u8 panel_mipi_dbi_magic[15] = { 'M', 'I', 'P', 'I', ' ', 'D', 'B', 'I',
3073
0, 0, 0, 0, 0, 0, 0 };
3174

@@ -276,6 +319,9 @@ static int panel_mipi_dbi_spi_probe(struct spi_device *spi)
276319
struct drm_device *drm;
277320
struct mipi_dbi *dbi;
278321
struct gpio_desc *dc;
322+
unsigned int bpp;
323+
size_t buf_size;
324+
u32 formats[2];
279325
int ret;
280326

281327
dbidev = devm_drm_dev_alloc(dev, &panel_mipi_dbi_driver, struct mipi_dbi_dev, drm);
@@ -323,7 +369,14 @@ static int panel_mipi_dbi_spi_probe(struct spi_device *spi)
323369
if (IS_ERR(dbidev->driver_private))
324370
return PTR_ERR(dbidev->driver_private);
325371

326-
ret = mipi_dbi_dev_init(dbidev, &panel_mipi_dbi_pipe_funcs, &mode, 0);
372+
ret = panel_mipi_dbi_get_format(dev, formats, &bpp);
373+
if (ret)
374+
return ret;
375+
376+
buf_size = DIV_ROUND_UP(mode.hdisplay * mode.vdisplay * bpp, 8);
377+
ret = mipi_dbi_dev_init_with_formats(dbidev, &panel_mipi_dbi_pipe_funcs,
378+
formats, ARRAY_SIZE(formats),
379+
&mode, 0, buf_size);
327380
if (ret)
328381
return ret;
329382

0 commit comments

Comments
 (0)