1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
6 #include <drm/drm_atomic_helper.h>
7 #include <drm/drm_atomic.h>
8 #include <drm/drm_bridge.h>
9 #include <drm/drm_bridge_connector.h>
10 #include <drm/drm_crtc.h>
17 * dp_bridge_detect - callback to determine if connector is connected
18 * @bridge: Pointer to drm bridge structure
19 * Returns: Bridge's 'is connected' status
21 static enum drm_connector_status dp_bridge_detect(struct drm_bridge *bridge)
25 dp = to_dp_bridge(bridge)->dp_display;
27 drm_dbg_dp(dp->drm_dev, "is_connected = %s\n",
28 (dp->is_connected) ? "true" : "false");
30 return (dp->is_connected) ? connector_status_connected :
31 connector_status_disconnected;
34 static int dp_bridge_atomic_check(struct drm_bridge *bridge,
35 struct drm_bridge_state *bridge_state,
36 struct drm_crtc_state *crtc_state,
37 struct drm_connector_state *conn_state)
41 dp = to_dp_bridge(bridge)->dp_display;
43 drm_dbg_dp(dp->drm_dev, "is_connected = %s\n",
44 (dp->is_connected) ? "true" : "false");
47 * There is no protection in the DRM framework to check if the display
48 * pipeline has been already disabled before trying to disable it again.
49 * Hence if the sink is unplugged, the pipeline gets disabled, but the
50 * crtc->active is still true. Any attempt to set the mode or manually
51 * disable this encoder will result in the crash.
53 * TODO: add support for telling the DRM subsystem that the pipeline is
54 * disabled by the hardware and thus all access to it should be forbidden.
55 * After that this piece of code can be removed.
57 if (bridge->ops & DRM_BRIDGE_OP_HPD)
58 return (dp->is_connected) ? 0 : -ENOTCONN;
65 * dp_bridge_get_modes - callback to add drm modes via drm_mode_probed_add()
66 * @bridge: Poiner to drm bridge
67 * @connector: Pointer to drm connector structure
68 * Returns: Number of modes added
70 static int dp_bridge_get_modes(struct drm_bridge *bridge, struct drm_connector *connector)
78 dp = to_dp_bridge(bridge)->dp_display;
80 /* pluggable case assumes EDID is read when HPD */
81 if (dp->is_connected) {
82 rc = dp_display_get_modes(dp);
84 DRM_ERROR("failed to get DP sink modes, rc=%d\n", rc);
88 drm_dbg_dp(connector->dev, "No sink connected\n");
93 static const struct drm_bridge_funcs dp_bridge_ops = {
94 .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
95 .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
96 .atomic_reset = drm_atomic_helper_bridge_reset,
97 .enable = dp_bridge_enable,
98 .disable = dp_bridge_disable,
99 .post_disable = dp_bridge_post_disable,
100 .mode_set = dp_bridge_mode_set,
101 .mode_valid = dp_bridge_mode_valid,
102 .get_modes = dp_bridge_get_modes,
103 .detect = dp_bridge_detect,
104 .atomic_check = dp_bridge_atomic_check,
107 struct drm_bridge *dp_bridge_init(struct msm_dp *dp_display, struct drm_device *dev,
108 struct drm_encoder *encoder)
111 struct msm_dp_bridge *dp_bridge;
112 struct drm_bridge *bridge;
114 dp_bridge = devm_kzalloc(dev->dev, sizeof(*dp_bridge), GFP_KERNEL);
116 return ERR_PTR(-ENOMEM);
118 dp_bridge->dp_display = dp_display;
120 bridge = &dp_bridge->bridge;
121 bridge->funcs = &dp_bridge_ops;
122 bridge->type = dp_display->connector_type;
125 * Many ops only make sense for DP. Why?
126 * - Detect/HPD are used by DRM to know if a display is _physically_
127 * there, not whether the display is powered on / finished initting.
128 * On eDP we assume the display is always there because you can't
129 * know until power is applied. If we don't implement the ops DRM will
130 * assume our display is always there.
131 * - Currently eDP mode reading is driven by the panel driver. This
132 * allows the panel driver to properly power itself on to read the
135 if (!dp_display->is_edp) {
137 DRM_BRIDGE_OP_DETECT |
142 drm_bridge_add(bridge);
144 rc = drm_bridge_attach(encoder, bridge, NULL, DRM_BRIDGE_ATTACH_NO_CONNECTOR);
146 DRM_ERROR("failed to attach bridge, rc=%d\n", rc);
147 drm_bridge_remove(bridge);
152 if (dp_display->next_bridge) {
153 rc = drm_bridge_attach(encoder,
154 dp_display->next_bridge, bridge,
155 DRM_BRIDGE_ATTACH_NO_CONNECTOR);
157 DRM_ERROR("failed to attach panel bridge: %d\n", rc);
158 drm_bridge_remove(bridge);
166 /* connector initialization */
167 struct drm_connector *dp_drm_connector_init(struct msm_dp *dp_display, struct drm_encoder *encoder)
169 struct drm_connector *connector = NULL;
171 connector = drm_bridge_connector_init(dp_display->drm_dev, encoder);
172 if (IS_ERR(connector))
175 drm_connector_attach_encoder(connector, encoder);