Skip to content

Commit 01389b3

Browse files
Jason-JH.LinChun-Kuang Hu
authored andcommitted
drm/mediatek: Add connector dynamic selection capability
Add dynamic select available connector flow in mtk_drm_crtc_create() and mtk_drm_crtc_atomic_enable(). In mtk_drm_crtc_create(), if there is a connector routes array in drm driver data, all components definded in the connector routes array will be checked and their encoder_index will be set. In mtk_drm_crtc_atomic_enable(), crtc will check its encoder_index to identify which componet in the connector routes array should append. Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com> Signed-off-by: Nancy Lin <nancy.lin@mediatek.com> Signed-off-by: Nathan Lu <nathan.lu@mediatek.com> Tested-by: Fei Shao <fshao@chromium.org> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Reviewed-by: CK Hu <ck.hu@mediatek.com> Link: https://patchwork.kernel.org/project/dri-devel/patch/20231004024013.18956-6-jason-jh.lin@mediatek.com/ Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
1 parent a260f56 commit 01389b3

5 files changed

Lines changed: 120 additions & 7 deletions

File tree

drivers/gpu/drm/mediatek/mtk_drm_crtc.c

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ struct mtk_drm_crtc {
6363
struct mtk_mutex *mutex;
6464
unsigned int ddp_comp_nr;
6565
struct mtk_ddp_comp **ddp_comp;
66+
unsigned int num_conn_routes;
67+
const struct mtk_drm_route *conn_routes;
6668

6769
/* lock for display hardware access */
6870
struct mutex hw_lock;
@@ -647,6 +649,43 @@ static void mtk_drm_crtc_disable_vblank(struct drm_crtc *crtc)
647649
mtk_ddp_comp_disable_vblank(comp);
648650
}
649651

652+
static void mtk_drm_crtc_update_output(struct drm_crtc *crtc,
653+
struct drm_atomic_state *state)
654+
{
655+
int crtc_index = drm_crtc_index(crtc);
656+
int i;
657+
struct device *dev;
658+
struct drm_crtc_state *crtc_state = state->crtcs[crtc_index].new_state;
659+
struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
660+
struct mtk_drm_private *priv;
661+
unsigned int encoder_mask = crtc_state->encoder_mask;
662+
663+
if (!crtc_state->connectors_changed)
664+
return;
665+
666+
if (!mtk_crtc->num_conn_routes)
667+
return;
668+
669+
priv = ((struct mtk_drm_private *)crtc->dev->dev_private)->all_drm_private[crtc_index];
670+
dev = priv->dev;
671+
672+
dev_dbg(dev, "connector change:%d, encoder mask:0x%x for crtc:%d\n",
673+
crtc_state->connectors_changed, encoder_mask, crtc_index);
674+
675+
for (i = 0; i < mtk_crtc->num_conn_routes; i++) {
676+
unsigned int comp_id = mtk_crtc->conn_routes[i].route_ddp;
677+
struct mtk_ddp_comp *comp = &priv->ddp_comp[comp_id];
678+
679+
if (comp->encoder_index >= 0 &&
680+
(encoder_mask & BIT(comp->encoder_index))) {
681+
mtk_crtc->ddp_comp[mtk_crtc->ddp_comp_nr - 1] = comp;
682+
dev_dbg(dev, "Add comp_id: %d at path index %d\n",
683+
comp->id, mtk_crtc->ddp_comp_nr - 1);
684+
break;
685+
}
686+
}
687+
}
688+
650689
int mtk_drm_crtc_plane_check(struct drm_crtc *crtc, struct drm_plane *plane,
651690
struct mtk_plane_state *state)
652691
{
@@ -685,6 +724,8 @@ static void mtk_drm_crtc_atomic_enable(struct drm_crtc *crtc,
685724
return;
686725
}
687726

727+
mtk_drm_crtc_update_output(crtc, state);
728+
688729
ret = mtk_crtc_ddp_hw_init(mtk_crtc);
689730
if (ret) {
690731
pm_runtime_put(comp->dev);
@@ -884,7 +925,8 @@ struct device *mtk_drm_crtc_dma_dev_get(struct drm_crtc *crtc)
884925

885926
int mtk_drm_crtc_create(struct drm_device *drm_dev,
886927
const unsigned int *path, unsigned int path_len,
887-
int priv_data_index)
928+
int priv_data_index, const struct mtk_drm_route *conn_routes,
929+
unsigned int num_conn_routes)
888930
{
889931
struct mtk_drm_private *priv = drm_dev->dev_private;
890932
struct device *dev = drm_dev->dev;
@@ -935,7 +977,8 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
935977

936978
mtk_crtc->mmsys_dev = priv->mmsys_dev;
937979
mtk_crtc->ddp_comp_nr = path_len;
938-
mtk_crtc->ddp_comp = devm_kmalloc_array(dev, mtk_crtc->ddp_comp_nr,
980+
mtk_crtc->ddp_comp = devm_kmalloc_array(dev,
981+
mtk_crtc->ddp_comp_nr + (conn_routes ? 1 : 0),
939982
sizeof(*mtk_crtc->ddp_comp),
940983
GFP_KERNEL);
941984
if (!mtk_crtc->ddp_comp)
@@ -1038,5 +1081,30 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
10381081
init_waitqueue_head(&mtk_crtc->cb_blocking_queue);
10391082
}
10401083
#endif
1084+
1085+
if (conn_routes) {
1086+
for (i = 0; i < num_conn_routes; i++) {
1087+
unsigned int comp_id = conn_routes[i].route_ddp;
1088+
struct device_node *node = priv->comp_node[comp_id];
1089+
struct mtk_ddp_comp *comp = &priv->ddp_comp[comp_id];
1090+
1091+
if (!comp->dev) {
1092+
dev_dbg(dev, "comp_id:%d, Component %pOF not initialized\n",
1093+
comp_id, node);
1094+
/* mark encoder_index to -1, if route comp device is not enabled */
1095+
comp->encoder_index = -1;
1096+
continue;
1097+
}
1098+
1099+
mtk_ddp_comp_encoder_index_set(&priv->ddp_comp[comp_id]);
1100+
}
1101+
1102+
mtk_crtc->num_conn_routes = num_conn_routes;
1103+
mtk_crtc->conn_routes = conn_routes;
1104+
1105+
/* increase ddp_comp_nr at the end of mtk_drm_crtc_create */
1106+
mtk_crtc->ddp_comp_nr++;
1107+
}
1108+
10411109
return 0;
10421110
}

drivers/gpu/drm/mediatek/mtk_drm_crtc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <drm/drm_crtc.h>
1010
#include "mtk_drm_ddp_comp.h"
11+
#include "mtk_drm_drv.h"
1112
#include "mtk_drm_plane.h"
1213

1314
#define MTK_LUT_SIZE 512
@@ -18,7 +19,9 @@ void mtk_drm_crtc_commit(struct drm_crtc *crtc);
1819
int mtk_drm_crtc_create(struct drm_device *drm_dev,
1920
const unsigned int *path,
2021
unsigned int path_len,
21-
int priv_data_index);
22+
int priv_data_index,
23+
const struct mtk_drm_route *conn_routes,
24+
unsigned int num_conn_routes);
2225
int mtk_drm_crtc_plane_check(struct drm_crtc *crtc, struct drm_plane *plane,
2326
struct mtk_plane_state *state);
2427
void mtk_drm_crtc_async_update(struct drm_crtc *crtc, struct drm_plane *plane,

drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,31 @@ static bool mtk_drm_find_comp_in_ddp(struct device *dev,
507507
return false;
508508
}
509509

510+
static unsigned int mtk_drm_find_comp_in_ddp_conn_path(struct device *dev,
511+
const struct mtk_drm_route *routes,
512+
unsigned int num_routes,
513+
struct mtk_ddp_comp *ddp_comp)
514+
{
515+
int ret;
516+
unsigned int i;
517+
518+
if (!routes) {
519+
ret = -EINVAL;
520+
goto err;
521+
}
522+
523+
for (i = 0; i < num_routes; i++)
524+
if (dev == ddp_comp[routes[i].route_ddp].dev)
525+
return BIT(routes[i].crtc_id);
526+
527+
ret = -ENODEV;
528+
err:
529+
530+
DRM_INFO("Failed to find comp in ddp table, ret = %d\n", ret);
531+
532+
return 0;
533+
}
534+
510535
int mtk_ddp_comp_get_id(struct device_node *node,
511536
enum mtk_ddp_comp_type comp_type)
512537
{
@@ -538,7 +563,10 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
538563
private->data->third_len, private->ddp_comp))
539564
ret = BIT(2);
540565
else
541-
DRM_INFO("Failed to find comp in ddp table\n");
566+
ret = mtk_drm_find_comp_in_ddp_conn_path(dev,
567+
private->data->conn_routes,
568+
private->data->num_conn_routes,
569+
private->ddp_comp);
542570

543571
return ret;
544572
}

drivers/gpu/drm/mediatek/mtk_drm_drv.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,11 @@ static bool mtk_drm_find_mmsys_comp(struct mtk_drm_private *private, int comp_id
424424
if (drv_data->third_path[i] == comp_id)
425425
return true;
426426

427+
if (drv_data->num_conn_routes)
428+
for (i = 0; i < drv_data->num_conn_routes; i++)
429+
if (drv_data->conn_routes[i].route_ddp == comp_id)
430+
return true;
431+
427432
return false;
428433
}
429434

@@ -482,21 +487,23 @@ static int mtk_drm_kms_init(struct drm_device *drm)
482487

483488
if (i == CRTC_MAIN && priv_n->data->main_len) {
484489
ret = mtk_drm_crtc_create(drm, priv_n->data->main_path,
485-
priv_n->data->main_len, j);
490+
priv_n->data->main_len, j,
491+
priv_n->data->conn_routes,
492+
priv_n->data->num_conn_routes);
486493
if (ret)
487494
goto err_component_unbind;
488495

489496
continue;
490497
} else if (i == CRTC_EXT && priv_n->data->ext_len) {
491498
ret = mtk_drm_crtc_create(drm, priv_n->data->ext_path,
492-
priv_n->data->ext_len, j);
499+
priv_n->data->ext_len, j, NULL, 0);
493500
if (ret)
494501
goto err_component_unbind;
495502

496503
continue;
497504
} else if (i == CRTC_THIRD && priv_n->data->third_len) {
498505
ret = mtk_drm_crtc_create(drm, priv_n->data->third_path,
499-
priv_n->data->third_len, j);
506+
priv_n->data->third_len, j, NULL, 0);
500507
if (ret)
501508
goto err_component_unbind;
502509

drivers/gpu/drm/mediatek/mtk_drm_drv.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,20 @@ struct drm_fb_helper;
2828
struct drm_property;
2929
struct regmap;
3030

31+
struct mtk_drm_route {
32+
const unsigned int crtc_id;
33+
const unsigned int route_ddp;
34+
};
35+
3136
struct mtk_mmsys_driver_data {
3237
const unsigned int *main_path;
3338
unsigned int main_len;
3439
const unsigned int *ext_path;
3540
unsigned int ext_len;
3641
const unsigned int *third_path;
3742
unsigned int third_len;
43+
const struct mtk_drm_route *conn_routes;
44+
unsigned int num_conn_routes;
3845

3946
bool shadow_register;
4047
unsigned int mmsys_id;

0 commit comments

Comments
 (0)