Skip to content

Commit 2dd8075

Browse files
Enric Balletbo i SerraChun-Kuang Hu
authored andcommitted
drm/mediatek: mtk_dsi: Use the drm_panel_bridge API
Replace the manual panel handling code by a drm_panel_bridge. This simplifies the driver and allows all components in the display pipeline to be treated as bridges, paving the way to generic connector handling. Signed-off-by: Enric Balletbo i Serra <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Acked-by: Sam Ravnborg <[email protected]> Signed-off-by: Chun-Kuang Hu <[email protected]>
1 parent 45880ff commit 2dd8075

File tree

1 file changed

+14
-159
lines changed

1 file changed

+14
-159
lines changed

drivers/gpu/drm/mediatek/mtk_dsi.c

Lines changed: 14 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ struct mtk_dsi {
182182
struct mipi_dsi_host host;
183183
struct drm_encoder encoder;
184184
struct drm_bridge bridge;
185-
struct drm_connector conn;
186-
struct drm_panel *panel;
187185
struct drm_bridge *next_bridge;
188186
struct phy *phy;
189187

@@ -212,11 +210,6 @@ static inline struct mtk_dsi *bridge_to_dsi(struct drm_bridge *b)
212210
return container_of(b, struct mtk_dsi, bridge);
213211
}
214212

215-
static inline struct mtk_dsi *connector_to_dsi(struct drm_connector *c)
216-
{
217-
return container_of(c, struct mtk_dsi, conn);
218-
}
219-
220213
static inline struct mtk_dsi *host_to_dsi(struct mipi_dsi_host *h)
221214
{
222215
return container_of(h, struct mtk_dsi, host);
@@ -679,16 +672,7 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi)
679672
mtk_dsi_lane0_ulp_mode_leave(dsi);
680673
mtk_dsi_clk_hs_mode(dsi, 0);
681674

682-
if (dsi->panel) {
683-
if (drm_panel_prepare(dsi->panel)) {
684-
DRM_ERROR("failed to prepare the panel\n");
685-
goto err_disable_digital_clk;
686-
}
687-
}
688-
689675
return 0;
690-
err_disable_digital_clk:
691-
clk_disable_unprepare(dsi->digital_clk);
692676
err_disable_engine_clk:
693677
clk_disable_unprepare(dsi->engine_clk);
694678
err_phy_power_off:
@@ -715,15 +699,7 @@ static void mtk_dsi_poweroff(struct mtk_dsi *dsi)
715699
*/
716700
mtk_dsi_stop(dsi);
717701

718-
if (!mtk_dsi_switch_to_cmd_mode(dsi, VM_DONE_INT_FLAG, 500)) {
719-
if (dsi->panel) {
720-
if (drm_panel_unprepare(dsi->panel)) {
721-
DRM_ERROR("failed to unprepare the panel\n");
722-
return;
723-
}
724-
}
725-
}
726-
702+
mtk_dsi_switch_to_cmd_mode(dsi, VM_DONE_INT_FLAG, 500);
727703
mtk_dsi_reset_engine(dsi);
728704
mtk_dsi_lane0_ulp_mode_enter(dsi);
729705
mtk_dsi_clk_ulp_mode_enter(dsi);
@@ -754,54 +730,27 @@ static void mtk_output_dsi_enable(struct mtk_dsi *dsi)
754730

755731
mtk_dsi_start(dsi);
756732

757-
if (dsi->panel) {
758-
if (drm_panel_enable(dsi->panel)) {
759-
DRM_ERROR("failed to enable the panel\n");
760-
goto err_dsi_power_off;
761-
}
762-
}
763-
764733
dsi->enabled = true;
765-
766-
return;
767-
err_dsi_power_off:
768-
mtk_dsi_stop(dsi);
769-
mtk_dsi_poweroff(dsi);
770734
}
771735

772736
static void mtk_output_dsi_disable(struct mtk_dsi *dsi)
773737
{
774738
if (!dsi->enabled)
775739
return;
776740

777-
if (dsi->panel) {
778-
if (drm_panel_disable(dsi->panel)) {
779-
DRM_ERROR("failed to disable the panel\n");
780-
return;
781-
}
782-
}
783-
784741
mtk_dsi_poweroff(dsi);
785742

786743
dsi->enabled = false;
787744
}
788745

789-
static int mtk_dsi_create_conn_enc(struct drm_device *drm, struct mtk_dsi *dsi);
790-
static void mtk_dsi_destroy_conn_enc(struct mtk_dsi *dsi);
791-
792746
static int mtk_dsi_bridge_attach(struct drm_bridge *bridge,
793747
enum drm_bridge_attach_flags flags)
794748
{
795749
struct mtk_dsi *dsi = bridge_to_dsi(bridge);
796750

797-
return mtk_dsi_create_conn_enc(bridge->dev, dsi);
798-
}
799-
800-
static void mtk_dsi_bridge_detach(struct drm_bridge *bridge)
801-
{
802-
struct mtk_dsi *dsi = bridge_to_dsi(bridge);
803-
804-
mtk_dsi_destroy_conn_enc(dsi);
751+
/* Attach the panel or bridge to the dsi bridge */
752+
return drm_bridge_attach(bridge->encoder, dsi->next_bridge,
753+
&dsi->bridge, flags);
805754
}
806755

807756
static void mtk_dsi_bridge_mode_set(struct drm_bridge *bridge,
@@ -827,101 +776,13 @@ static void mtk_dsi_bridge_enable(struct drm_bridge *bridge)
827776
mtk_output_dsi_enable(dsi);
828777
}
829778

830-
static int mtk_dsi_connector_get_modes(struct drm_connector *connector)
831-
{
832-
struct mtk_dsi *dsi = connector_to_dsi(connector);
833-
834-
return drm_panel_get_modes(dsi->panel, connector);
835-
}
836-
837779
static const struct drm_bridge_funcs mtk_dsi_bridge_funcs = {
838780
.attach = mtk_dsi_bridge_attach,
839-
.detach = mtk_dsi_bridge_detach,
840781
.disable = mtk_dsi_bridge_disable,
841782
.enable = mtk_dsi_bridge_enable,
842783
.mode_set = mtk_dsi_bridge_mode_set,
843784
};
844785

845-
static const struct drm_connector_funcs mtk_dsi_connector_funcs = {
846-
.fill_modes = drm_helper_probe_single_connector_modes,
847-
.destroy = drm_connector_cleanup,
848-
.reset = drm_atomic_helper_connector_reset,
849-
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
850-
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
851-
};
852-
853-
static const struct drm_connector_helper_funcs
854-
mtk_dsi_connector_helper_funcs = {
855-
.get_modes = mtk_dsi_connector_get_modes,
856-
};
857-
858-
static int mtk_dsi_create_connector(struct drm_device *drm, struct mtk_dsi *dsi)
859-
{
860-
int ret;
861-
862-
ret = drm_connector_init(drm, &dsi->conn, &mtk_dsi_connector_funcs,
863-
DRM_MODE_CONNECTOR_DSI);
864-
if (ret) {
865-
DRM_ERROR("Failed to connector init to drm\n");
866-
return ret;
867-
}
868-
869-
drm_connector_helper_add(&dsi->conn, &mtk_dsi_connector_helper_funcs);
870-
871-
dsi->conn.dpms = DRM_MODE_DPMS_OFF;
872-
drm_connector_attach_encoder(&dsi->conn, &dsi->encoder);
873-
874-
if (dsi->panel) {
875-
ret = drm_panel_attach(dsi->panel, &dsi->conn);
876-
if (ret) {
877-
DRM_ERROR("Failed to attach panel to drm\n");
878-
goto err_connector_cleanup;
879-
}
880-
}
881-
882-
return 0;
883-
884-
err_connector_cleanup:
885-
drm_connector_cleanup(&dsi->conn);
886-
return ret;
887-
}
888-
889-
static int mtk_dsi_create_conn_enc(struct drm_device *drm, struct mtk_dsi *dsi)
890-
{
891-
int ret;
892-
893-
/* If there's a next bridge, attach to it and let it create the connector */
894-
if (dsi->next_bridge) {
895-
ret = drm_bridge_attach(&dsi->encoder, dsi->next_bridge, NULL,
896-
0);
897-
if (ret) {
898-
DRM_ERROR("Failed to attach bridge to drm\n");
899-
goto err_encoder_cleanup;
900-
}
901-
} else {
902-
/* Otherwise create our own connector and attach to a panel */
903-
ret = mtk_dsi_create_connector(drm, dsi);
904-
if (ret)
905-
goto err_encoder_cleanup;
906-
}
907-
908-
return 0;
909-
910-
err_encoder_cleanup:
911-
drm_encoder_cleanup(&dsi->encoder);
912-
return ret;
913-
}
914-
915-
static void mtk_dsi_destroy_conn_enc(struct mtk_dsi *dsi)
916-
{
917-
drm_encoder_cleanup(&dsi->encoder);
918-
/* Skip connector cleanup if creation was delegated to the bridge */
919-
if (dsi->conn.dev)
920-
drm_connector_cleanup(&dsi->conn);
921-
if (dsi->panel)
922-
drm_panel_detach(dsi->panel);
923-
}
924-
925786
static void mtk_dsi_ddp_start(struct mtk_ddp_comp *comp)
926787
{
927788
struct mtk_dsi *dsi = container_of(comp, struct mtk_dsi, ddp_comp);
@@ -950,20 +811,6 @@ static int mtk_dsi_host_attach(struct mipi_dsi_host *host,
950811
dsi->format = device->format;
951812
dsi->mode_flags = device->mode_flags;
952813

953-
if (dsi->conn.dev)
954-
drm_helper_hpd_irq_event(dsi->conn.dev);
955-
956-
return 0;
957-
}
958-
959-
static int mtk_dsi_host_detach(struct mipi_dsi_host *host,
960-
struct mipi_dsi_device *device)
961-
{
962-
struct mtk_dsi *dsi = host_to_dsi(host);
963-
964-
if (dsi->conn.dev)
965-
drm_helper_hpd_irq_event(dsi->conn.dev);
966-
967814
return 0;
968815
}
969816

@@ -1107,7 +954,6 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host,
1107954

1108955
static const struct mipi_dsi_host_ops mtk_dsi_ops = {
1109956
.attach = mtk_dsi_host_attach,
1110-
.detach = mtk_dsi_host_detach,
1111957
.transfer = mtk_dsi_host_transfer,
1112958
};
1113959

@@ -1182,6 +1028,7 @@ static int mtk_dsi_probe(struct platform_device *pdev)
11821028
{
11831029
struct mtk_dsi *dsi;
11841030
struct device *dev = &pdev->dev;
1031+
struct drm_panel *panel;
11851032
struct resource *regs;
11861033
int irq_num;
11871034
int comp_id;
@@ -1200,10 +1047,18 @@ static int mtk_dsi_probe(struct platform_device *pdev)
12001047
}
12011048

12021049
ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0,
1203-
&dsi->panel, &dsi->next_bridge);
1050+
&panel, &dsi->next_bridge);
12041051
if (ret)
12051052
goto err_unregister_host;
12061053

1054+
if (panel) {
1055+
dsi->next_bridge = devm_drm_panel_bridge_add(dev, panel);
1056+
if (IS_ERR(dsi->next_bridge)) {
1057+
ret = PTR_ERR(dsi->next_bridge);
1058+
goto err_unregister_host;
1059+
}
1060+
}
1061+
12071062
dsi->driver_data = of_device_get_match_data(dev);
12081063

12091064
dsi->engine_clk = devm_clk_get(dev, "engine");

0 commit comments

Comments
 (0)