Skip to content

Commit 9ff6df4

Browse files
mwalleChun-Kuang Hu
authored andcommitted
drm/mediatek: dpi/dsi: Fix possible_crtcs calculation
mtk_find_possible_crtcs() assumes that the main path will always have the CRTC with id 0, the ext id 1 and the third id 2. This is only true if the paths are all available. But paths are optional (see also comment in mtk_drm_kms_init()), e.g. the main path might not be enabled or available at all. Then the CRTC IDs will shift one up, e.g. ext will be 0 and the third path will be 1. To fix that, dynamically calculate the IDs by the presence of the paths. While at it, make the return code a signed one and return -ENODEV if no path is found and handle the error in the callers. Fixes: 5aa8e76 ("drm/mediatek: dpi/dsi: Change the getting possible_crtc way") Suggested-by: Nícolas F. R. A. Prado <[email protected]> Signed-off-by: Michael Walle <[email protected]> Link: https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/ Signed-off-by: Chun-Kuang Hu <[email protected]>
1 parent 45b70f7 commit 9ff6df4

File tree

4 files changed

+80
-39
lines changed

4 files changed

+80
-39
lines changed

drivers/gpu/drm/mediatek/mtk_ddp_comp.c

Lines changed: 71 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -514,29 +514,42 @@ static bool mtk_ddp_comp_find(struct device *dev,
514514
return false;
515515
}
516516

517-
static unsigned int mtk_ddp_comp_find_in_route(struct device *dev,
518-
const struct mtk_drm_route *routes,
519-
unsigned int num_routes,
520-
struct mtk_ddp_comp *ddp_comp)
517+
static int mtk_ddp_comp_find_in_route(struct device *dev,
518+
const struct mtk_drm_route *routes,
519+
unsigned int num_routes,
520+
struct mtk_ddp_comp *ddp_comp)
521521
{
522-
int ret;
523522
unsigned int i;
524523

525-
if (!routes) {
526-
ret = -EINVAL;
527-
goto err;
528-
}
524+
if (!routes)
525+
return -EINVAL;
529526

530527
for (i = 0; i < num_routes; i++)
531528
if (dev == ddp_comp[routes[i].route_ddp].dev)
532529
return BIT(routes[i].crtc_id);
533530

534-
ret = -ENODEV;
535-
err:
531+
return -ENODEV;
532+
}
536533

537-
DRM_INFO("Failed to find comp in ddp table, ret = %d\n", ret);
534+
static bool mtk_ddp_path_available(const unsigned int *path,
535+
unsigned int path_len,
536+
struct device_node **comp_node)
537+
{
538+
unsigned int i;
538539

539-
return 0;
540+
if (!path || !path_len)
541+
return false;
542+
543+
for (i = 0U; i < path_len; i++) {
544+
/* OVL_ADAPTOR doesn't have a device node */
545+
if (path[i] == DDP_COMPONENT_DRM_OVL_ADAPTOR)
546+
continue;
547+
548+
if (!comp_node[path[i]])
549+
return false;
550+
}
551+
552+
return true;
540553
}
541554

542555
int mtk_ddp_comp_get_id(struct device_node *node,
@@ -554,31 +567,53 @@ int mtk_ddp_comp_get_id(struct device_node *node,
554567
return -EINVAL;
555568
}
556569

557-
unsigned int mtk_find_possible_crtcs(struct drm_device *drm, struct device *dev)
570+
int mtk_find_possible_crtcs(struct drm_device *drm, struct device *dev)
558571
{
559572
struct mtk_drm_private *private = drm->dev_private;
560-
unsigned int ret = 0;
561-
562-
if (mtk_ddp_comp_find(dev,
563-
private->data->main_path,
564-
private->data->main_len,
565-
private->ddp_comp))
566-
ret = BIT(0);
567-
else if (mtk_ddp_comp_find(dev,
568-
private->data->ext_path,
569-
private->data->ext_len,
570-
private->ddp_comp))
571-
ret = BIT(1);
572-
else if (mtk_ddp_comp_find(dev,
573-
private->data->third_path,
574-
private->data->third_len,
575-
private->ddp_comp))
576-
ret = BIT(2);
577-
else
578-
ret = mtk_ddp_comp_find_in_route(dev,
579-
private->data->conn_routes,
580-
private->data->num_conn_routes,
581-
private->ddp_comp);
573+
const struct mtk_mmsys_driver_data *data;
574+
struct mtk_drm_private *priv_n;
575+
int i = 0, j;
576+
int ret;
577+
578+
for (j = 0; j < private->data->mmsys_dev_num; j++) {
579+
priv_n = private->all_drm_private[j];
580+
data = priv_n->data;
581+
582+
if (mtk_ddp_path_available(data->main_path, data->main_len,
583+
priv_n->comp_node)) {
584+
if (mtk_ddp_comp_find(dev, data->main_path,
585+
data->main_len,
586+
priv_n->ddp_comp))
587+
return BIT(i);
588+
i++;
589+
}
590+
591+
if (mtk_ddp_path_available(data->ext_path, data->ext_len,
592+
priv_n->comp_node)) {
593+
if (mtk_ddp_comp_find(dev, data->ext_path,
594+
data->ext_len,
595+
priv_n->ddp_comp))
596+
return BIT(i);
597+
i++;
598+
}
599+
600+
if (mtk_ddp_path_available(data->third_path, data->third_len,
601+
priv_n->comp_node)) {
602+
if (mtk_ddp_comp_find(dev, data->third_path,
603+
data->third_len,
604+
priv_n->ddp_comp))
605+
return BIT(i);
606+
i++;
607+
}
608+
}
609+
610+
ret = mtk_ddp_comp_find_in_route(dev,
611+
private->data->conn_routes,
612+
private->data->num_conn_routes,
613+
private->ddp_comp);
614+
615+
if (ret < 0)
616+
DRM_INFO("Failed to find comp in ddp table, ret = %d\n", ret);
582617

583618
return ret;
584619
}

drivers/gpu/drm/mediatek/mtk_ddp_comp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static inline void mtk_ddp_comp_encoder_index_set(struct mtk_ddp_comp *comp)
330330

331331
int mtk_ddp_comp_get_id(struct device_node *node,
332332
enum mtk_ddp_comp_type comp_type);
333-
unsigned int mtk_find_possible_crtcs(struct drm_device *drm, struct device *dev);
333+
int mtk_find_possible_crtcs(struct drm_device *drm, struct device *dev);
334334
int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
335335
unsigned int comp_id);
336336
enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);

drivers/gpu/drm/mediatek/mtk_dpi.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,10 @@ static int mtk_dpi_bind(struct device *dev, struct device *master, void *data)
805805
return ret;
806806
}
807807

808-
dpi->encoder.possible_crtcs = mtk_find_possible_crtcs(drm_dev, dpi->dev);
808+
ret = mtk_find_possible_crtcs(drm_dev, dpi->dev);
809+
if (ret < 0)
810+
goto err_cleanup;
811+
dpi->encoder.possible_crtcs = ret;
809812

810813
ret = drm_bridge_attach(&dpi->encoder, &dpi->bridge, NULL,
811814
DRM_BRIDGE_ATTACH_NO_CONNECTOR);

drivers/gpu/drm/mediatek/mtk_dsi.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,10 @@ static int mtk_dsi_encoder_init(struct drm_device *drm, struct mtk_dsi *dsi)
837837
return ret;
838838
}
839839

840-
dsi->encoder.possible_crtcs = mtk_find_possible_crtcs(drm, dsi->host.dev);
840+
ret = mtk_find_possible_crtcs(drm, dsi->host.dev);
841+
if (ret < 0)
842+
goto err_cleanup_encoder;
843+
dsi->encoder.possible_crtcs = ret;
841844

842845
ret = drm_bridge_attach(&dsi->encoder, &dsi->bridge, NULL,
843846
DRM_BRIDGE_ATTACH_NO_CONNECTOR);

0 commit comments

Comments
 (0)