hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/gpu/drm/drm_simple_kms_helper.c
....@@ -1,19 +1,17 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2016 Noralf Trønnes
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation; either version 2 of the License, or
7
- * (at your option) any later version.
84 */
95
10
-#include <drm/drmP.h>
6
+#include <linux/module.h>
7
+#include <linux/slab.h>
8
+
119 #include <drm/drm_atomic.h>
1210 #include <drm/drm_atomic_helper.h>
13
-#include <drm/drm_crtc_helper.h>
11
+#include <drm/drm_bridge.h>
1412 #include <drm/drm_plane_helper.h>
13
+#include <drm/drm_probe_helper.h>
1514 #include <drm/drm_simple_kms_helper.h>
16
-#include <linux/slab.h>
1715
1816 /**
1917 * DOC: overview
....@@ -28,11 +26,50 @@
2826 * entity. Some flexibility for code reuse is provided through a separately
2927 * allocated &drm_connector object and supporting optional &drm_bridge
3028 * encoder drivers.
29
+ *
30
+ * Many drivers require only a very simple encoder that fulfills the minimum
31
+ * requirements of the display pipeline and does not add additional
32
+ * functionality. The function drm_simple_encoder_init() provides an
33
+ * implementation of such an encoder.
3134 */
3235
33
-static const struct drm_encoder_funcs drm_simple_kms_encoder_funcs = {
36
+static const struct drm_encoder_funcs drm_simple_encoder_funcs_cleanup = {
3437 .destroy = drm_encoder_cleanup,
3538 };
39
+
40
+/**
41
+ * drm_simple_encoder_init - Initialize a preallocated encoder with
42
+ * basic functionality.
43
+ * @dev: drm device
44
+ * @encoder: the encoder to initialize
45
+ * @encoder_type: user visible type of the encoder
46
+ *
47
+ * Initialises a preallocated encoder that has no further functionality.
48
+ * Settings for possible CRTC and clones are left to their initial values.
49
+ * The encoder will be cleaned up automatically as part of the mode-setting
50
+ * cleanup.
51
+ *
52
+ * The caller of drm_simple_encoder_init() is responsible for freeing
53
+ * the encoder's memory after the encoder has been cleaned up. At the
54
+ * moment this only works reliably if the encoder data structure is
55
+ * stored in the device structure. Free the encoder's memory as part of
56
+ * the device release function.
57
+ *
58
+ * FIXME: Later improvements to DRM's resource management may allow for
59
+ * an automated kfree() of the encoder's memory.
60
+ *
61
+ * Returns:
62
+ * Zero on success, error code on failure.
63
+ */
64
+int drm_simple_encoder_init(struct drm_device *dev,
65
+ struct drm_encoder *encoder,
66
+ int encoder_type)
67
+{
68
+ return drm_encoder_init(dev, encoder,
69
+ &drm_simple_encoder_funcs_cleanup,
70
+ encoder_type, NULL);
71
+}
72
+EXPORT_SYMBOL(drm_simple_encoder_init);
3673
3774 static enum drm_mode_status
3875 drm_simple_kms_crtc_mode_valid(struct drm_crtc *crtc,
....@@ -45,7 +82,7 @@
4582 /* Anything goes */
4683 return MODE_OK;
4784
48
- return pipe->funcs->mode_valid(crtc, mode);
85
+ return pipe->funcs->mode_valid(pipe, mode);
4986 }
5087
5188 static int drm_simple_kms_crtc_check(struct drm_crtc *crtc,
....@@ -190,6 +227,13 @@
190227 pipe->funcs->cleanup_fb(pipe, state);
191228 }
192229
230
+static bool drm_simple_kms_format_mod_supported(struct drm_plane *plane,
231
+ uint32_t format,
232
+ uint64_t modifier)
233
+{
234
+ return modifier == DRM_FORMAT_MOD_LINEAR;
235
+}
236
+
193237 static const struct drm_plane_helper_funcs drm_simple_kms_plane_helper_funcs = {
194238 .prepare_fb = drm_simple_kms_plane_prepare_fb,
195239 .cleanup_fb = drm_simple_kms_plane_cleanup_fb,
....@@ -204,6 +248,7 @@
204248 .reset = drm_atomic_helper_plane_reset,
205249 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
206250 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
251
+ .format_mod_supported = drm_simple_kms_format_mod_supported,
207252 };
208253
209254 /**
....@@ -223,7 +268,7 @@
223268 int drm_simple_display_pipe_attach_bridge(struct drm_simple_display_pipe *pipe,
224269 struct drm_bridge *bridge)
225270 {
226
- return drm_bridge_attach(&pipe->encoder, bridge, NULL);
271
+ return drm_bridge_attach(&pipe->encoder, bridge, NULL, 0);
227272 }
228273 EXPORT_SYMBOL(drm_simple_display_pipe_attach_bridge);
229274
....@@ -282,8 +327,7 @@
282327 return ret;
283328
284329 encoder->possible_crtcs = drm_crtc_mask(crtc);
285
- ret = drm_encoder_init(dev, encoder, &drm_simple_kms_encoder_funcs,
286
- DRM_MODE_ENCODER_NONE, NULL);
330
+ ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_NONE);
287331 if (ret || !connector)
288332 return ret;
289333