WIP FPC-III support
[linux/fpc-iii.git] / drivers / gpu / drm / msm / edp / edp_bridge.c
blobc69a37e0c708277c73dfa5c609c8baae8b33ecd9
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
4 */
6 #include "edp.h"
8 struct edp_bridge {
9 struct drm_bridge base;
10 struct msm_edp *edp;
12 #define to_edp_bridge(x) container_of(x, struct edp_bridge, base)
14 void edp_bridge_destroy(struct drm_bridge *bridge)
18 static void edp_bridge_pre_enable(struct drm_bridge *bridge)
20 struct edp_bridge *edp_bridge = to_edp_bridge(bridge);
21 struct msm_edp *edp = edp_bridge->edp;
23 DBG("");
24 msm_edp_ctrl_power(edp->ctrl, true);
27 static void edp_bridge_enable(struct drm_bridge *bridge)
29 DBG("");
32 static void edp_bridge_disable(struct drm_bridge *bridge)
34 DBG("");
37 static void edp_bridge_post_disable(struct drm_bridge *bridge)
39 struct edp_bridge *edp_bridge = to_edp_bridge(bridge);
40 struct msm_edp *edp = edp_bridge->edp;
42 DBG("");
43 msm_edp_ctrl_power(edp->ctrl, false);
46 static void edp_bridge_mode_set(struct drm_bridge *bridge,
47 const struct drm_display_mode *mode,
48 const struct drm_display_mode *adjusted_mode)
50 struct drm_device *dev = bridge->dev;
51 struct drm_connector *connector;
52 struct edp_bridge *edp_bridge = to_edp_bridge(bridge);
53 struct msm_edp *edp = edp_bridge->edp;
55 DBG("set mode: " DRM_MODE_FMT, DRM_MODE_ARG(mode));
57 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
58 struct drm_encoder *encoder = connector->encoder;
59 struct drm_bridge *first_bridge;
61 if (!connector->encoder)
62 continue;
64 first_bridge = drm_bridge_chain_get_first_bridge(encoder);
65 if (bridge == first_bridge) {
66 msm_edp_ctrl_timing_cfg(edp->ctrl,
67 adjusted_mode, &connector->display_info);
68 break;
73 static const struct drm_bridge_funcs edp_bridge_funcs = {
74 .pre_enable = edp_bridge_pre_enable,
75 .enable = edp_bridge_enable,
76 .disable = edp_bridge_disable,
77 .post_disable = edp_bridge_post_disable,
78 .mode_set = edp_bridge_mode_set,
81 /* initialize bridge */
82 struct drm_bridge *msm_edp_bridge_init(struct msm_edp *edp)
84 struct drm_bridge *bridge = NULL;
85 struct edp_bridge *edp_bridge;
86 int ret;
88 edp_bridge = devm_kzalloc(edp->dev->dev,
89 sizeof(*edp_bridge), GFP_KERNEL);
90 if (!edp_bridge) {
91 ret = -ENOMEM;
92 goto fail;
95 edp_bridge->edp = edp;
97 bridge = &edp_bridge->base;
98 bridge->funcs = &edp_bridge_funcs;
100 ret = drm_bridge_attach(edp->encoder, bridge, NULL, 0);
101 if (ret)
102 goto fail;
104 return bridge;
106 fail:
107 if (bridge)
108 edp_bridge_destroy(bridge);
110 return ERR_PTR(ret);