Skip to content

Commit 9e7a74a

Browse files
author
Thomas Zimmermann
committed
drm/ast: dp501: Use struct drm_edid and helpers
Convert DP501 support to struct drm_edid and its helpers. Simplifies and modernizes the EDID handling. The driver reads 4 bytes at once, but the overall read length is now variable. Therefore update the EDID read loop to never return more than the requested bytes. v2: - fix reading EDID data Signed-off-by: Thomas Zimmermann <[email protected]> Reviewed-by: Jocelyn Falempe <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent bbad009 commit 9e7a74a

File tree

1 file changed

+22
-37
lines changed

1 file changed

+22
-37
lines changed

drivers/gpu/drm/ast/ast_dp501.c

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -318,32 +318,30 @@ static bool ast_dp501_is_connected(struct ast_device *ast)
318318
return true;
319319
}
320320

321-
static bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata)
321+
static int ast_dp512_read_edid_block(void *data, u8 *buf, unsigned int block, size_t len)
322322
{
323-
struct ast_device *ast = to_ast_device(dev);
324-
u32 i, boot_address, offset, data;
325-
u32 *pEDIDidx;
323+
struct ast_device *ast = data;
324+
size_t rdlen = round_up(len, 4);
325+
u32 i, boot_address, offset, ediddata;
326326

327-
if (!ast_dp501_is_connected(ast))
328-
return false;
327+
if (block > (512 / EDID_LENGTH))
328+
return -EIO;
329+
330+
offset = AST_DP501_EDID_DATA + block * EDID_LENGTH;
329331

330332
if (ast->config_mode == ast_use_p2a) {
331333
boot_address = get_fw_base(ast);
332334

333-
/* Read EDID */
334-
offset = AST_DP501_EDID_DATA;
335-
for (i = 0; i < 128; i += 4) {
336-
data = ast_mindwm(ast, boot_address + offset + i);
337-
pEDIDidx = (u32 *)(ediddata + i);
338-
*pEDIDidx = data;
335+
for (i = 0; i < rdlen; i += 4) {
336+
ediddata = ast_mindwm(ast, boot_address + offset + i);
337+
memcpy(buf, &ediddata, min((len - i), 4));
338+
buf += 4;
339339
}
340340
} else {
341-
/* Read EDID */
342-
offset = AST_DP501_EDID_DATA;
343-
for (i = 0; i < 128; i += 4) {
344-
data = readl(ast->dp501_fw_buf + offset + i);
345-
pEDIDidx = (u32 *)(ediddata + i);
346-
*pEDIDidx = data;
341+
for (i = 0; i < rdlen; i += 4) {
342+
ediddata = readl(ast->dp501_fw_buf + offset + i);
343+
memcpy(buf, &ediddata, min((len - i), 4));
344+
buf += 4;
347345
}
348346
}
349347

@@ -511,29 +509,16 @@ static const struct drm_encoder_helper_funcs ast_dp501_encoder_helper_funcs = {
511509

512510
static int ast_dp501_connector_helper_get_modes(struct drm_connector *connector)
513511
{
514-
void *edid;
515-
bool succ;
512+
struct ast_device *ast = to_ast_device(connector->dev);
513+
const struct drm_edid *drm_edid;
516514
int count;
517515

518-
edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
519-
if (!edid)
520-
goto err_drm_connector_update_edid_property;
521-
522-
succ = ast_dp501_read_edid(connector->dev, edid);
523-
if (!succ)
524-
goto err_kfree;
525-
526-
drm_connector_update_edid_property(connector, edid);
527-
count = drm_add_edid_modes(connector, edid);
528-
kfree(edid);
516+
drm_edid = drm_edid_read_custom(connector, ast_dp512_read_edid_block, ast);
517+
drm_edid_connector_update(connector, drm_edid);
518+
count = drm_edid_connector_add_modes(connector);
519+
drm_edid_free(drm_edid);
529520

530521
return count;
531-
532-
err_kfree:
533-
kfree(edid);
534-
err_drm_connector_update_edid_property:
535-
drm_connector_update_edid_property(connector, NULL);
536-
return 0;
537522
}
538523

539524
static int ast_dp501_connector_helper_detect_ctx(struct drm_connector *connector,

0 commit comments

Comments
 (0)