Skip to content

Commit 8c3b7d2

Browse files
author
Thomas Zimmermann
committed
drm/ast: astdp: Inline mode-index calculation
Programming the astdp transmitter chip requires a magic value for individual modes. Inline the helper for calculating the value into its only caller (i.e., the encoder's atomic_mode_set). With further refactoring, the atomic check will be able to detect invalid modes before attempting to program them. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250204133209.403327-3-tzimmermann@suse.de
1 parent 3214403 commit 8c3b7d2

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

drivers/gpu/drm/ast/ast_dp.c

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ to_ast_astdp_connector_state(const struct drm_connector_state *state)
5252
return container_of(state, struct ast_astdp_connector_state, base);
5353
}
5454

55-
static int __ast_astdp_get_mode_index(unsigned int hdisplay, unsigned int vdisplay)
55+
static int ast_astdp_get_mode_index(unsigned int hdisplay, unsigned int vdisplay)
5656
{
5757
const struct ast_astdp_mode_index_table_entry *entry = ast_astdp_mode_index_table;
5858

@@ -65,35 +65,6 @@ static int __ast_astdp_get_mode_index(unsigned int hdisplay, unsigned int vdispl
6565
return -EINVAL;
6666
}
6767

68-
static int ast_astdp_get_mode_index(const struct ast_vbios_enhtable *vmode)
69-
{
70-
int mode_index;
71-
u8 refresh_rate_index;
72-
73-
mode_index = __ast_astdp_get_mode_index(vmode->hde, vmode->vde);
74-
if (mode_index < 0)
75-
return mode_index;
76-
77-
if (vmode->refresh_rate_index < 1 || vmode->refresh_rate_index > 255)
78-
return -EINVAL;
79-
refresh_rate_index = vmode->refresh_rate_index - 1;
80-
81-
/* FIXME: Why are we doing this? */
82-
switch (mode_index) {
83-
case ASTDP_1280x800_60_RB:
84-
case ASTDP_1440x900_60_RB:
85-
case ASTDP_1600x900_60_RB:
86-
case ASTDP_1680x1050_60_RB:
87-
mode_index = (u8)(mode_index - (u8)refresh_rate_index);
88-
break;
89-
default:
90-
mode_index = (u8)(mode_index + (u8)refresh_rate_index);
91-
break;
92-
}
93-
94-
return mode_index;
95-
}
96-
9768
static bool ast_astdp_is_connected(struct ast_device *ast)
9869
{
9970
if (!ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xDF, AST_IO_VGACRDF_HPD))
@@ -333,13 +304,32 @@ static void ast_astdp_encoder_helper_atomic_mode_set(struct drm_encoder *encoder
333304
struct drm_device *dev = encoder->dev;
334305
struct ast_device *ast = to_ast_device(dev);
335306
struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
307+
const struct ast_vbios_enhtable *vmode = ast_crtc_state->vmode;
336308
int mode_index;
309+
u8 refresh_rate_index;
337310
u8 vgacre0, vgacre1, vgacre2;
338311

339-
mode_index = ast_astdp_get_mode_index(ast_crtc_state->vmode);
312+
mode_index = ast_astdp_get_mode_index(vmode->hde, vmode->vde);
340313
if (drm_WARN_ON(dev, mode_index < 0))
341314
return;
342315

316+
if (drm_WARN_ON(dev, vmode->refresh_rate_index < 1 || vmode->refresh_rate_index > 255))
317+
return;
318+
refresh_rate_index = vmode->refresh_rate_index - 1;
319+
320+
/* FIXME: Why are we doing this? */
321+
switch (mode_index) {
322+
case ASTDP_1280x800_60_RB:
323+
case ASTDP_1440x900_60_RB:
324+
case ASTDP_1600x900_60_RB:
325+
case ASTDP_1680x1050_60_RB:
326+
mode_index = (u8)(mode_index - (u8)refresh_rate_index);
327+
break;
328+
default:
329+
mode_index = (u8)(mode_index + (u8)refresh_rate_index);
330+
break;
331+
}
332+
343333
/*
344334
* CRE0[7:0]: MISC0 ((0x00: 18-bpp) or (0x20: 24-bpp)
345335
* CRE1[7:0]: MISC1 (default: 0x00)

0 commit comments

Comments
 (0)