Skip to content

Commit e4572f9

Browse files
sresuperna9999
authored andcommitted
drm/panel: sitronix-st7789v: avoid hardcoding polarity info
Add polarity information via mode and bus flags, so that they are no longer hardcoded and forward the information to the DRM stack. This is required for adding panels with different settings. Reviewed-by: Michael Riesch <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]> Signed-off-by: Neil Armstrong <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 7a62887 commit e4572f9

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

drivers/gpu/drm/panel/panel-sitronix-st7789v.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define ST7789V_RGBCTRL_VSYNC_HIGH BIT(3)
2929
#define ST7789V_RGBCTRL_HSYNC_HIGH BIT(2)
3030
#define ST7789V_RGBCTRL_PCLK_HIGH BIT(1)
31+
#define ST7789V_RGBCTRL_DE_LOW BIT(0)
3132
#define ST7789V_RGBCTRL_VBP(n) ((n) & 0x7f)
3233
#define ST7789V_RGBCTRL_HBP(n) ((n) & 0x1f)
3334

@@ -112,6 +113,7 @@
112113
struct st7789_panel_info {
113114
const struct drm_display_mode *mode;
114115
u32 bus_format;
116+
u32 bus_flags;
115117
bool invert_mode;
116118
};
117119

@@ -168,12 +170,15 @@ static const struct drm_display_mode default_mode = {
168170
.vtotal = 320 + 8 + 4 + 4,
169171
.width_mm = 61,
170172
.height_mm = 103,
173+
.flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
171174
};
172175

173176
static const struct st7789_panel_info default_panel = {
174177
.mode = &default_mode,
175178
.invert_mode = true,
176179
.bus_format = MEDIA_BUS_FMT_RGB666_1X18,
180+
.bus_flags = DRM_BUS_FLAG_DE_HIGH |
181+
DRM_BUS_FLAG_PIXDATA_SAMPLE_NEGEDGE,
177182
};
178183

179184
static int st7789v_get_modes(struct drm_panel *panel,
@@ -198,6 +203,7 @@ static int st7789v_get_modes(struct drm_panel *panel,
198203
connector->display_info.bpc = 6;
199204
connector->display_info.width_mm = ctx->info->mode->width_mm;
200205
connector->display_info.height_mm = ctx->info->mode->height_mm;
206+
connector->display_info.bus_flags = ctx->info->bus_flags;
201207
drm_display_info_set_bus_formats(&connector->display_info,
202208
&ctx->info->bus_format, 1);
203209

@@ -207,7 +213,7 @@ static int st7789v_get_modes(struct drm_panel *panel,
207213
static int st7789v_prepare(struct drm_panel *panel)
208214
{
209215
struct st7789v *ctx = panel_to_st7789v(panel);
210-
u8 pixel_fmt;
216+
u8 pixel_fmt, polarity;
211217
int ret;
212218

213219
switch (ctx->info->bus_format) {
@@ -225,6 +231,16 @@ static int st7789v_prepare(struct drm_panel *panel)
225231

226232
pixel_fmt = (pixel_fmt << 4) | pixel_fmt;
227233

234+
polarity = 0;
235+
if (ctx->info->mode->flags & DRM_MODE_FLAG_PVSYNC)
236+
polarity |= ST7789V_RGBCTRL_VSYNC_HIGH;
237+
if (ctx->info->mode->flags & DRM_MODE_FLAG_PHSYNC)
238+
polarity |= ST7789V_RGBCTRL_HSYNC_HIGH;
239+
if (ctx->info->bus_flags & DRM_BUS_FLAG_PIXDATA_SAMPLE_NEGEDGE)
240+
polarity |= ST7789V_RGBCTRL_PCLK_HIGH;
241+
if (ctx->info->bus_flags & DRM_BUS_FLAG_DE_LOW)
242+
polarity |= ST7789V_RGBCTRL_DE_LOW;
243+
228244
ret = regulator_enable(ctx->power);
229245
if (ret)
230246
return ret;
@@ -340,9 +356,7 @@ static int st7789v_prepare(struct drm_panel *panel)
340356
ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_RGBCTRL_CMD));
341357
ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_RGBCTRL_WO |
342358
ST7789V_RGBCTRL_RCM(2) |
343-
ST7789V_RGBCTRL_VSYNC_HIGH |
344-
ST7789V_RGBCTRL_HSYNC_HIGH |
345-
ST7789V_RGBCTRL_PCLK_HIGH));
359+
polarity));
346360
ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_RGBCTRL_VBP(8)));
347361
ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_RGBCTRL_HBP(20)));
348362

0 commit comments

Comments
 (0)