Add dynamic connector selection mechanism
Subsystems (3)
v5 cover Add dynamic connector selection mechanism
To support DSI and eDP as main display connector without modifying mtk-drm driver, we add the dynamic connector selection mechanism.
Change in v5:
1. Change conn_routes array to single component enum id.
Change in v4:
1. Change variable naming from conn_route_num to num_conn_routes.
2. Change he encoder_index function return valuew from int to unsigned int.
Change in v3:
1. Change max_num comparison statement to max().
Change in v2:
1. rebase on linux-next: next-20230426
2. Fix alphabetical order and max_num condition check problem.
Change in v1:
1. based on mediatek-drm maintainer's tree / mediatek-drm-next branch:
https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/log/?h=mediatek-drm-next
Jason-JH.Lin (2):
drm/mediatek: Add ability to support dynamic connector selection drm/mediatek: Add DSI support for mt8188 vdosys0
drivers/gpu/drm/mediatek/mtk_disp_drv.h | 2 + drivers/gpu/drm/mediatek/mtk_dpi.c | 9 +++ drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 87 ++++++++++++++++++++- drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 5 +- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 27 +++++++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 8 ++ drivers/gpu/drm/mediatek/mtk_drm_drv.c | 38 +++++++-- drivers/gpu/drm/mediatek/mtk_drm_drv.h | 7 ++ drivers/gpu/drm/mediatek/mtk_dsi.c | 9 +++ 9 files changed, 182 insertions(+), 10 deletions(-)
Signature · 1 line
2.18.0
PATCH v5 1/2 drm/mediatek: Add ability to support dynamic connector selection
1. Move output drm connector from each ddp_path array to connector array.
2. Add dynamic select available connector flow in crtc create and enable.
--- drivers/gpu/drm/mediatek/mtk_disp_drv.h | 1 + drivers/gpu/drm/mediatek/mtk_dpi.c | 9 +++ drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 87 ++++++++++++++++++++- drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 5 +- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 26 ++++++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 8 ++ drivers/gpu/drm/mediatek/mtk_drm_drv.c | 37 +++++++-- drivers/gpu/drm/mediatek/mtk_drm_drv.h | 7 ++ 8 files changed, 170 insertions(+), 10 deletions(-)
drivers/gpu/drm/mediatek/mtk_disp_drv.h +1 -0
@@ -44,6 +44,7 @@ void mtk_dither_set_common(void __iomem *regs, struct cmdq_client_reg *cmdq_reg,void mtk_dpi_start (struct device *dev);void mtk_dpi_stop (struct device *dev); +unsigned int mtk_dpi_encoder_index (struct device *dev);void mtk_dsi_ddp_start (struct device *dev);void mtk_dsi_ddp_stop (struct device *dev);
drivers/gpu/drm/mediatek/mtk_dpi.c +9 -0
@@ -782,6 +782,15 @@ void mtk_dpi_stop(struct device *dev)mtk_dpi_power_off (dpi); } +unsigned int mtk_dpi_encoder_index (struct device *dev) +{ +struct mtk_dpi *dpi =dev_get_drvdata (dev); +unsigned int encoder_index =drm_encoder_index (&dpi->encoder); + +dev_dbg (dev,"encoder index:%d" , encoder_index); +return encoder_index; +} +static int mtk_dpi_bind (struct device *dev,struct device *master,void *data) {struct mtk_dpi *dpi =dev_get_drvdata (dev);
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +85 -2
119 lines not on this page · raw message
drivers/gpu/drm/mediatek/mtk_drm_crtc.h +4 -1
@@ -8,6 +8,7 @@#include <drm/drm_crtc.h> #include "mtk_drm_ddp_comp.h" +#include "mtk_drm_drv.h" #include "mtk_drm_plane.h" #define MTK_LUT_SIZE 512
@@ -18,7 +19,9 @@ void mtk_drm_crtc_commit(struct drm_crtc *crtc);int mtk_drm_crtc_create (struct drm_device *drm_dev,const unsigned int *path,unsigned int path_len, -int priv_data_index); +int priv_data_index, +const struct mtk_drm_route *conn_routes, +unsigned int num_conn_routes);int mtk_drm_crtc_plane_check (struct drm_crtc *crtc,struct drm_plane *plane,struct mtk_plane_state *state); void mtk_drm_crtc_async_update(struct drm_crtc *crtc, struct drm_plane *plane,
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +26 -0
@@ -304,6 +304,7 @@ static const struct mtk_ddp_comp_funcs ddp_dither = {static const struct mtk_ddp_comp_funcs ddp_dpi = { .start = mtk_dpi_start, .stop = mtk_dpi_stop, + .encoder_index = mtk_dpi_encoder_index, };static const struct mtk_ddp_comp_funcs ddp_dsc = {
@@ -507,6 +508,25 @@ static bool mtk_drm_find_comp_in_ddp(struct device *dev,return false; } +static int mtk_drm_find_comp_in_ddp_conn_path (struct device *dev, +const struct mtk_drm_route *routes, +unsigned int routes_num, +struct mtk_ddp_comp *ddp_comp) +{ +unsigned int i; + +if (!routes) +return 0 ; + +for (i =0 ; i < routes_num; i++) +if (dev == ddp_comp[routes[i].route_ddp].dev) +return BIT (routes[i].crtc_id); + +DRM_INFO ("Failed to find comp in ddp connector table\n" ); + +return 0 ; +} +int mtk_ddp_comp_get_id (struct device_node *node,enum mtk_ddp_comp_type comp_type) {
@@ -538,6 +558,12 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm, private->data->third_len, private->ddp_comp)) ret =BIT (2 ); else + ret =mtk_drm_find_comp_in_ddp_conn_path (dev, + private->data->conn_routes, + private->data->num_conn_routes, + private->ddp_comp); + +if (ret ==0 )DRM_INFO ("Failed to find comp in ddp table\n" );return ret;
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +8 -0
@@ -80,6 +80,7 @@ struct mtk_ddp_comp_funcs {void (*disconnect)(struct device *dev,struct device *mmsys_dev,unsigned int next);void (*add)(struct device *dev,struct mtk_mutex *mutex);void (*remove)(struct device *dev,struct mtk_mutex *mutex); +unsigned int (*encoder_index)(struct device *dev); };struct mtk_ddp_comp {
@@ -87,6 +88,7 @@ struct mtk_ddp_comp {int irq;unsigned int id;const struct mtk_ddp_comp_funcs *funcs; +unsigned int encoder_index; };static inline int mtk_ddp_comp_clk_enable (struct mtk_ddp_comp *comp)
@@ -275,6 +277,12 @@ static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct devreturn false; } +static inline void mtk_ddp_comp_encoder_index_set (struct mtk_ddp_comp *comp) +{ +if (comp->funcs && comp->funcs->encoder_index) + comp->encoder_index = comp->funcs->encoder_index (comp->dev); +} +int mtk_ddp_comp_get_id (struct device_node *node,enum mtk_ddp_comp_type comp_type); unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
drivers/gpu/drm/mediatek/mtk_drm_drv.c +30 -7
@@ -185,7 +185,10 @@ static const unsigned int mt8188_mtk_ddp_main[] = {DDP_COMPONENT_GAMMA ,DDP_COMPONENT_POSTMASK0 , DDP_COMPONENT_DITHER0, - DDP_COMPONENT_DP_INTF0, +}; + +static const struct mtk_drm_route mt8188_mtk_ddp_main_routes[] = { + {0 ,DDP_COMPONENT_DP_INTF0 }, }; static const unsigned int mt8192_mtk_ddp_main[] = {
@@ -287,6 +290,9 @@ static const struct mtk_mmsys_driver_data mt8186_mmsys_driver_data = {static const struct mtk_mmsys_driver_data mt8188_vdosys0_driver_data = { .main_path = mt8188_mtk_ddp_main, .main_len =ARRAY_SIZE (mt8188_mtk_ddp_main), + .conn_routes = mt8188_mtk_ddp_main_routes, + .num_conn_routes =ARRAY_SIZE (mt8188_mtk_ddp_main_routes), + .mmsys_dev_num =1 , };static const struct mtk_mmsys_driver_data mt8192_mmsys_driver_data = {
@@ -350,6 +356,7 @@ static bool mtk_drm_get_all_drm_priv(struct device *dev) {struct mtk_drm_private *drm_priv =dev_get_drvdata (dev);struct mtk_drm_private *all_drm_priv[MAX_CRTC ]; +struct mtk_drm_private *temp_drm_priv;struct device_node *phandle = dev->parent->of_node;const struct of_device_id *of_id;struct device_node *node;
@@ -372,9 +379,18 @@ static bool mtk_drm_get_all_drm_priv(struct device *dev)if (!drm_dev || !dev_get_drvdata (drm_dev))continue ; - all_drm_priv[cnt] =dev_get_drvdata (drm_dev); -if (all_drm_priv[cnt] && all_drm_priv[cnt]->mtk_drm_bound) - cnt++; + temp_drm_priv =dev_get_drvdata (drm_dev); +if (temp_drm_priv) { +if (temp_drm_priv->mtk_drm_bound) + cnt++; + +if (temp_drm_priv->data->main_len) + all_drm_priv[0 ] = temp_drm_priv; +else if (temp_drm_priv->data->ext_len) + all_drm_priv[1 ] = temp_drm_priv; +else if (temp_drm_priv->data->third_len) + all_drm_priv[2 ] = temp_drm_priv; + } }if (drm_priv->data->mmsys_dev_num == cnt) {
@@ -408,6 +424,11 @@ static bool mtk_drm_find_mmsys_comp(struct mtk_drm_private *private, int comp_idif (drv_data->third_path[i] == comp_id)return true; +if (drv_data->num_conn_routes) +for (i =0 ; i < drv_data->num_conn_routes; i++) +if (drv_data->conn_routes[i].route_ddp == comp_id) +return true; +return false; }
@@ -466,21 +487,23 @@ static int mtk_drm_kms_init(struct drm_device *drm)if (i ==0 && priv_n->data->main_len) { ret =mtk_drm_crtc_create (drm, priv_n->data->main_path, - priv_n->data->main_len, j); + priv_n->data->main_len, j, + priv_n->data->conn_routes, + priv_n->data->num_conn_routes);if (ret) goto err_component_unbind;continue ; }else if (i ==1 && priv_n->data->ext_len) { ret =mtk_drm_crtc_create (drm, priv_n->data->ext_path, - priv_n->data->ext_len, j); + priv_n->data->ext_len, j,NULL ,0 );if (ret) goto err_component_unbind;continue ; }else if (i ==2 && priv_n->data->third_len) { ret =mtk_drm_crtc_create (drm, priv_n->data->third_path, - priv_n->data->third_len, j); + priv_n->data->third_len, j,NULL ,0 );if (ret) goto err_component_unbind;
drivers/gpu/drm/mediatek/mtk_drm_drv.h +7 -0
@@ -22,6 +22,11 @@ struct drm_fb_helper;struct drm_property ;struct regmap ; +struct mtk_drm_route { +const unsigned int crtc_id; +const unsigned int route_ddp; +}; +struct mtk_mmsys_driver_data {const unsigned int *main_path;unsigned int main_len;
@@ -29,6 +34,8 @@ struct mtk_mmsys_driver_data {unsigned int ext_len;const unsigned int *third_path;unsigned int third_len; +const struct mtk_drm_route *conn_routes; +unsigned int num_conn_routes;bool shadow_register;unsigned int mmsys_id;
Signature · 1 line
2.18.0
PATCH v5 2/2 drm/mediatek: Add DSI support for mt8188 vdosys0
In reply to Jason-JH.LinAdd DSI as main display output for mt8188 vdosys0.
--- drivers/gpu/drm/mediatek/mtk_disp_drv.h | 1 + drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 1 + drivers/gpu/drm/mediatek/mtk_drm_drv.c | 1 + drivers/gpu/drm/mediatek/mtk_dsi.c | 9 +++++++++ 4 files changed, 12 insertions(+)
drivers/gpu/drm/mediatek/mtk_disp_drv.h +1 -0
@@ -48,6 +48,7 @@ unsigned int mtk_dpi_encoder_index(struct device *dev);void mtk_dsi_ddp_start (struct device *dev);void mtk_dsi_ddp_stop (struct device *dev); +unsigned int mtk_dsi_encoder_index (struct device *dev);int mtk_gamma_clk_enable (struct device *dev);void mtk_gamma_clk_disable (struct device *dev);
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +1 -0
@@ -318,6 +318,7 @@ static const struct mtk_ddp_comp_funcs ddp_dsc = {static const struct mtk_ddp_comp_funcs ddp_dsi = { .start = mtk_dsi_ddp_start, .stop = mtk_dsi_ddp_stop, + .encoder_index = mtk_dsi_encoder_index, };static const struct mtk_ddp_comp_funcs ddp_gamma = {
drivers/gpu/drm/mediatek/mtk_drm_drv.c +1 -0
@@ -189,6 +189,7 @@ static const unsigned int mt8188_mtk_ddp_main[] = {static const struct mtk_drm_route mt8188_mtk_ddp_main_routes[] = { {0 ,DDP_COMPONENT_DP_INTF0 }, + {0 ,DDP_COMPONENT_DSI0 }, };static const unsigned int mt8192_mtk_ddp_main[] = {
drivers/gpu/drm/mediatek/mtk_dsi.c +9 -0
@@ -865,6 +865,15 @@ static int mtk_dsi_encoder_init(struct drm_device *drm, struct mtk_dsi *dsi)return ret; } +unsigned int mtk_dsi_encoder_index (struct device *dev) +{ +struct mtk_dsi *dsi =dev_get_drvdata (dev); +unsigned int encoder_index =drm_encoder_index (&dsi->encoder); + +dev_dbg (dev,"encoder index:%d" , encoder_index); +return encoder_index; +} +static int mtk_dsi_bind (struct device *dev,struct device *master,void *data) {int ret;
Signature · 1 line
2.18.0