File Index
Files and directories
Sign in
FILE

dp_drm.c

File preview with syntax highlighting.

linux-6.19.14/drivers/gpu/drm/msm/dp/dp_drm.c C
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4 */
  5
  6#include <linux/string_choices.h>
  7#include <drm/drm_atomic_helper.h>
  8#include <drm/drm_atomic.h>
  9#include <drm/drm_bridge.h>
 10#include <drm/drm_bridge_connector.h>
 11#include <drm/drm_crtc.h>
 12
 13#include "msm_drv.h"
 14#include "msm_kms.h"
 15#include "dp_audio.h"
 16#include "dp_drm.h"
 17
 18/**
 19 * msm_dp_bridge_detect - callback to determine if connector is connected
 20 * @bridge: Pointer to drm bridge structure
 21 * @connector: Pointer to drm connector structure
 22 * Returns: Bridge's 'is connected' status
 23 */
 24static enum drm_connector_status
 25msm_dp_bridge_detect(struct drm_bridge *bridge, struct drm_connector *connector)
 26{
 27	struct msm_dp *dp;
 28
 29	dp = to_dp_bridge(bridge)->msm_dp_display;
 30
 31	drm_dbg_dp(dp->drm_dev, "link_ready = %s\n",
 32		str_true_false(dp->link_ready));
 33
 34	return (dp->link_ready) ? connector_status_connected :
 35					connector_status_disconnected;
 36}
 37
 38static int msm_dp_bridge_atomic_check(struct drm_bridge *bridge,
 39			    struct drm_bridge_state *bridge_state,
 40			    struct drm_crtc_state *crtc_state,
 41			    struct drm_connector_state *conn_state)
 42{
 43	struct msm_dp *dp;
 44
 45	dp = to_dp_bridge(bridge)->msm_dp_display;
 46
 47	drm_dbg_dp(dp->drm_dev, "link_ready = %s\n",
 48		str_true_false(dp->link_ready));
 49
 50	/*
 51	 * There is no protection in the DRM framework to check if the display
 52	 * pipeline has been already disabled before trying to disable it again.
 53	 * Hence if the sink is unplugged, the pipeline gets disabled, but the
 54	 * crtc->active is still true. Any attempt to set the mode or manually
 55	 * disable this encoder will result in the crash.
 56	 *
 57	 * TODO: add support for telling the DRM subsystem that the pipeline is
 58	 * disabled by the hardware and thus all access to it should be forbidden.
 59	 * After that this piece of code can be removed.
 60	 */
 61	if (bridge->ops & DRM_BRIDGE_OP_HPD)
 62		return (dp->link_ready) ? 0 : -ENOTCONN;
 63
 64	return 0;
 65}
 66
 67
 68/**
 69 * msm_dp_bridge_get_modes - callback to add drm modes via drm_mode_probed_add()
 70 * @bridge: Poiner to drm bridge
 71 * @connector: Pointer to drm connector structure
 72 * Returns: Number of modes added
 73 */
 74static int msm_dp_bridge_get_modes(struct drm_bridge *bridge, struct drm_connector *connector)
 75{
 76	int rc = 0;
 77	struct msm_dp *dp;
 78
 79	if (!connector)
 80		return 0;
 81
 82	dp = to_dp_bridge(bridge)->msm_dp_display;
 83
 84	/* pluggable case assumes EDID is read when HPD */
 85	if (dp->link_ready) {
 86		rc = msm_dp_display_get_modes(dp);
 87		if (rc <= 0) {
 88			DRM_ERROR("failed to get DP sink modes, rc=%d\n", rc);
 89			return rc;
 90		}
 91	} else {
 92		drm_dbg_dp(connector->dev, "No sink connected\n");
 93	}
 94	return rc;
 95}
 96
 97static void msm_dp_bridge_debugfs_init(struct drm_bridge *bridge, struct dentry *root)
 98{
 99	struct msm_dp *dp = to_dp_bridge(bridge)->msm_dp_display;
100
101	msm_dp_display_debugfs_init(dp, root, false);
102}
103
104static const struct drm_bridge_funcs msm_dp_bridge_ops = {
105	.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
106	.atomic_destroy_state   = drm_atomic_helper_bridge_destroy_state,
107	.atomic_reset           = drm_atomic_helper_bridge_reset,
108	.atomic_enable          = msm_dp_bridge_atomic_enable,
109	.atomic_disable         = msm_dp_bridge_atomic_disable,
110	.atomic_post_disable    = msm_dp_bridge_atomic_post_disable,
111	.mode_set     = msm_dp_bridge_mode_set,
112	.mode_valid   = msm_dp_bridge_mode_valid,
113	.get_modes    = msm_dp_bridge_get_modes,
114	.detect       = msm_dp_bridge_detect,
115	.atomic_check = msm_dp_bridge_atomic_check,
116	.hpd_enable   = msm_dp_bridge_hpd_enable,
117	.hpd_disable  = msm_dp_bridge_hpd_disable,
118	.hpd_notify   = msm_dp_bridge_hpd_notify,
119	.debugfs_init = msm_dp_bridge_debugfs_init,
120
121	.dp_audio_prepare = msm_dp_audio_prepare,
122	.dp_audio_shutdown = msm_dp_audio_shutdown,
123};
124
125static int msm_edp_bridge_atomic_check(struct drm_bridge *drm_bridge,
126				   struct drm_bridge_state *bridge_state,
127				   struct drm_crtc_state *crtc_state,
128				   struct drm_connector_state *conn_state)
129{
130	struct msm_dp *dp = to_dp_bridge(drm_bridge)->msm_dp_display;
131
132	if (WARN_ON(!conn_state))
133		return -ENODEV;
134
135	conn_state->self_refresh_aware = dp->psr_supported;
136
137	if (!conn_state->crtc || !crtc_state)
138		return 0;
139
140	if (crtc_state->self_refresh_active && !dp->psr_supported)
141		return -EINVAL;
142
143	return 0;
144}
145
146static void msm_edp_bridge_atomic_enable(struct drm_bridge *drm_bridge,
147					 struct drm_atomic_state *state)
148{
149	struct drm_crtc *crtc;
150	struct drm_crtc_state *old_crtc_state;
151	struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(drm_bridge);
152	struct msm_dp *dp = msm_dp_bridge->msm_dp_display;
153
154	/*
155	 * Check the old state of the crtc to determine if the panel
156	 * was put into psr state previously by the msm_edp_bridge_atomic_disable.
157	 * If the panel is in psr, just exit psr state and skip the full
158	 * bridge enable sequence.
159	 */
160	crtc = drm_atomic_get_new_crtc_for_encoder(state,
161						   drm_bridge->encoder);
162	if (!crtc)
163		return;
164
165	old_crtc_state = drm_atomic_get_old_crtc_state(state, crtc);
166
167	if (old_crtc_state && old_crtc_state->self_refresh_active) {
168		msm_dp_display_set_psr(dp, false);
169		return;
170	}
171
172	msm_dp_bridge_atomic_enable(drm_bridge, state);
173}
174
175static void msm_edp_bridge_atomic_disable(struct drm_bridge *drm_bridge,
176					  struct drm_atomic_state *atomic_state)
177{
178	struct drm_crtc *crtc;
179	struct drm_crtc_state *new_crtc_state = NULL, *old_crtc_state = NULL;
180	struct msm_dp_bridge *msm_dp_bridge = to_dp_bridge(drm_bridge);
181	struct msm_dp *dp = msm_dp_bridge->msm_dp_display;
182
183	crtc = drm_atomic_get_old_crtc_for_encoder(atomic_state,
184						   drm_bridge->encoder);
185	if (!crtc)
186		goto out;
187
188	new_crtc_state = drm_atomic_get_new_crtc_state(atomic_state, crtc);
189	if (!new_crtc_state)
190		goto out;
191
192	old_crtc_state = drm_atomic_get_old_crtc_state(atomic_state, crtc);
193	if (!old_crtc_state)
194		goto out;
195
196	/*
197	 * Set self refresh mode if current crtc state is active.
198	 *
199	 * If old crtc state is active, then this is a display disable
200	 * call while the sink is in psr state. So, exit psr here.
201	 * The eDP controller will be disabled in the
202	 * msm_edp_bridge_atomic_post_disable function.
203	 *
204	 * We observed sink is stuck in self refresh if psr exit is skipped
205	 * when display disable occurs while the sink is in psr state.
206	 */
207	if (new_crtc_state->self_refresh_active) {
208		msm_dp_display_set_psr(dp, true);
209		return;
210	} else if (old_crtc_state->self_refresh_active) {
211		msm_dp_display_set_psr(dp, false);
212		return;
213	}
214
215out:
216	msm_dp_bridge_atomic_disable(drm_bridge, atomic_state);
217}
218
219static void msm_edp_bridge_atomic_post_disable(struct drm_bridge *drm_bridge,
220					       struct drm_atomic_state *atomic_state)
221{
222	struct drm_crtc *crtc;
223	struct drm_crtc_state *new_crtc_state = NULL;
224
225	crtc = drm_atomic_get_old_crtc_for_encoder(atomic_state,
226						   drm_bridge->encoder);
227	if (!crtc)
228		return;
229
230	new_crtc_state = drm_atomic_get_new_crtc_state(atomic_state, crtc);
231	if (!new_crtc_state)
232		return;
233
234	/*
235	 * Self refresh mode is already set in msm_edp_bridge_atomic_disable.
236	 */
237	if (new_crtc_state->self_refresh_active)
238		return;
239
240	msm_dp_bridge_atomic_post_disable(drm_bridge, atomic_state);
241}
242
243/**
244 * msm_edp_bridge_mode_valid - callback to determine if specified mode is valid
245 * @bridge: Pointer to drm bridge structure
246 * @info: display info
247 * @mode: Pointer to drm mode structure
248 * Returns: Validity status for specified mode
249 */
250static enum drm_mode_status msm_edp_bridge_mode_valid(struct drm_bridge *bridge,
251					  const struct drm_display_info *info,
252					  const struct drm_display_mode *mode)
253{
254	struct msm_dp *dp;
255	int mode_pclk_khz = mode->clock;
256
257	dp = to_dp_bridge(bridge)->msm_dp_display;
258
259	if (!dp || !mode_pclk_khz || !dp->connector) {
260		DRM_ERROR("invalid params\n");
261		return -EINVAL;
262	}
263
264	if (msm_dp_wide_bus_available(dp))
265		mode_pclk_khz /= 2;
266
267	if (mode_pclk_khz > DP_MAX_PIXEL_CLK_KHZ)
268		return MODE_CLOCK_HIGH;
269
270	/*
271	 * The eDP controller currently does not have a reliable way of
272	 * enabling panel power to read sink capabilities. So, we rely
273	 * on the panel driver to populate only supported modes for now.
274	 */
275	return MODE_OK;
276}
277
278static void msm_edp_bridge_debugfs_init(struct drm_bridge *bridge, struct dentry *root)
279{
280	struct msm_dp *dp = to_dp_bridge(bridge)->msm_dp_display;
281
282	msm_dp_display_debugfs_init(dp, root, true);
283}
284
285static const struct drm_bridge_funcs msm_edp_bridge_ops = {
286	.atomic_enable = msm_edp_bridge_atomic_enable,
287	.atomic_disable = msm_edp_bridge_atomic_disable,
288	.atomic_post_disable = msm_edp_bridge_atomic_post_disable,
289	.mode_set = msm_dp_bridge_mode_set,
290	.mode_valid = msm_edp_bridge_mode_valid,
291	.atomic_reset = drm_atomic_helper_bridge_reset,
292	.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
293	.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
294	.atomic_check = msm_edp_bridge_atomic_check,
295	.debugfs_init = msm_edp_bridge_debugfs_init,
296};
297
298int msm_dp_bridge_init(struct msm_dp *msm_dp_display, struct drm_device *dev,
299		   struct drm_encoder *encoder, bool yuv_supported)
300{
301	int rc;
302	struct msm_dp_bridge *msm_dp_bridge;
303	struct drm_bridge *bridge;
304
305	msm_dp_bridge = devm_drm_bridge_alloc(dev->dev, struct msm_dp_bridge, bridge,
306					      msm_dp_display->is_edp ? &msm_edp_bridge_ops :
307					      &msm_dp_bridge_ops);
308	if (IS_ERR(msm_dp_bridge))
309		return PTR_ERR(msm_dp_bridge);
310
311	msm_dp_bridge->msm_dp_display = msm_dp_display;
312
313	bridge = &msm_dp_bridge->bridge;
314	bridge->type = msm_dp_display->connector_type;
315	bridge->ycbcr_420_allowed = yuv_supported;
316
317	/*
318	 * Many ops only make sense for DP. Why?
319	 * - Detect/HPD are used by DRM to know if a display is _physically_
320	 *   there, not whether the display is powered on / finished initting.
321	 *   On eDP we assume the display is always there because you can't
322	 *   know until power is applied. If we don't implement the ops DRM will
323	 *   assume our display is always there.
324	 * - Currently eDP mode reading is driven by the panel driver. This
325	 *   allows the panel driver to properly power itself on to read the
326	 *   modes.
327	 */
328	if (!msm_dp_display->is_edp) {
329		bridge->ops =
330			DRM_BRIDGE_OP_DP_AUDIO |
331			DRM_BRIDGE_OP_DETECT |
332			DRM_BRIDGE_OP_HPD |
333			DRM_BRIDGE_OP_MODES;
334		bridge->hdmi_audio_dev = &msm_dp_display->pdev->dev;
335		bridge->hdmi_audio_max_i2s_playback_channels = 8;
336		bridge->hdmi_audio_dai_port = -1;
337	}
338
339	rc = devm_drm_bridge_add(dev->dev, bridge);
340	if (rc) {
341		DRM_ERROR("failed to add bridge, rc=%d\n", rc);
342
343		return rc;
344	}
345
346	rc = drm_bridge_attach(encoder, bridge, NULL, DRM_BRIDGE_ATTACH_NO_CONNECTOR);
347	if (rc) {
348		DRM_ERROR("failed to attach bridge, rc=%d\n", rc);
349
350		return rc;
351	}
352
353	if (msm_dp_display->next_bridge) {
354		rc = drm_bridge_attach(encoder,
355					msm_dp_display->next_bridge, bridge,
356					DRM_BRIDGE_ATTACH_NO_CONNECTOR);
357		if (rc < 0) {
358			DRM_ERROR("failed to attach panel bridge: %d\n", rc);
359			return rc;
360		}
361	}
362
363	return 0;
364}
365
366/* connector initialization */
367struct drm_connector *msm_dp_drm_connector_init(struct msm_dp *msm_dp_display,
368					    struct drm_encoder *encoder)
369{
370	struct drm_connector *connector = NULL;
371
372	connector = drm_bridge_connector_init(msm_dp_display->drm_dev, encoder);
373	if (IS_ERR(connector))
374		return connector;
375
376	if (!msm_dp_display->is_edp)
377		drm_connector_attach_dp_subconnector_property(connector);
378
379	drm_connector_attach_encoder(connector, encoder);
380
381	return connector;
382}
~/ Read-only file preview.