Skip to content

Commit

Permalink
drm/panel: sitronix-st7789v: add media bus format
Browse files Browse the repository at this point in the history
Add support for describing the media bus format in the
panel configuration and expose that to userspace. Since
both supported formats (RGB565 and RGB666) are using 6
bits per color also hardcode that information.

Reviewed-by: Michael Riesch <michael.riesch@wolfvision.net>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20230714013756.1546769-11-sre@kernel.org
  • Loading branch information
sre authored and superna9999 committed Aug 1, 2023
1 parent 4098d18 commit a4b563b
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions drivers/gpu/drm/panel/panel-sitronix-st7789v.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <linux/spi/spi.h>

#include <video/mipi_display.h>
#include <linux/media-bus-format.h>

#include <drm/drm_device.h>
#include <drm/drm_modes.h>
Expand Down Expand Up @@ -110,6 +111,7 @@

struct st7789_panel_info {
const struct drm_display_mode *mode;
u32 bus_format;
};

struct st7789v {
Expand Down Expand Up @@ -169,6 +171,7 @@ static const struct drm_display_mode default_mode = {

static const struct st7789_panel_info default_panel = {
.mode = &default_mode,
.bus_format = MEDIA_BUS_FMT_RGB666_1X18,
};

static int st7789v_get_modes(struct drm_panel *panel,
Expand All @@ -190,17 +193,36 @@ static int st7789v_get_modes(struct drm_panel *panel,
mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
drm_mode_probed_add(connector, mode);

connector->display_info.bpc = 6;
connector->display_info.width_mm = ctx->info->mode->width_mm;
connector->display_info.height_mm = ctx->info->mode->height_mm;
drm_display_info_set_bus_formats(&connector->display_info,
&ctx->info->bus_format, 1);

return 1;
}

static int st7789v_prepare(struct drm_panel *panel)
{
struct st7789v *ctx = panel_to_st7789v(panel);
u8 pixel_fmt;
int ret;

switch (ctx->info->bus_format) {
case MEDIA_BUS_FMT_RGB666_1X18:
pixel_fmt = MIPI_DCS_PIXEL_FMT_18BIT;
break;
case MEDIA_BUS_FMT_RGB565_1X16:
pixel_fmt = MIPI_DCS_PIXEL_FMT_16BIT;
break;
default:
dev_err(panel->dev, "unsupported bus format: %d\n",
ctx->info->bus_format);
return -EINVAL;
}

pixel_fmt = (pixel_fmt << 4) | pixel_fmt;

ret = regulator_enable(ctx->power);
if (ret)
return ret;
Expand All @@ -221,9 +243,7 @@ static int st7789v_prepare(struct drm_panel *panel)

ST7789V_TEST(ret, st7789v_write_command(ctx,
MIPI_DCS_SET_PIXEL_FORMAT));
ST7789V_TEST(ret, st7789v_write_data(ctx,
(MIPI_DCS_PIXEL_FMT_18BIT << 4) |
(MIPI_DCS_PIXEL_FMT_18BIT)));
ST7789V_TEST(ret, st7789v_write_data(ctx, pixel_fmt));

ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_PORCTRL_CMD));
ST7789V_TEST(ret, st7789v_write_data(ctx, 0xc));
Expand Down

0 comments on commit a4b563b

Please sign in to comment.