.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * 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. |
---|
8 | 4 | */ |
---|
9 | 5 | |
---|
10 | | -#include <drm/drmP.h> |
---|
| 6 | +#include <linux/module.h> |
---|
| 7 | +#include <linux/slab.h> |
---|
| 8 | + |
---|
11 | 9 | #include <drm/drm_atomic.h> |
---|
12 | 10 | #include <drm/drm_atomic_helper.h> |
---|
13 | | -#include <drm/drm_crtc_helper.h> |
---|
| 11 | +#include <drm/drm_bridge.h> |
---|
14 | 12 | #include <drm/drm_plane_helper.h> |
---|
| 13 | +#include <drm/drm_probe_helper.h> |
---|
15 | 14 | #include <drm/drm_simple_kms_helper.h> |
---|
16 | | -#include <linux/slab.h> |
---|
17 | 15 | |
---|
18 | 16 | /** |
---|
19 | 17 | * DOC: overview |
---|
.. | .. |
---|
28 | 26 | * entity. Some flexibility for code reuse is provided through a separately |
---|
29 | 27 | * allocated &drm_connector object and supporting optional &drm_bridge |
---|
30 | 28 | * 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. |
---|
31 | 34 | */ |
---|
32 | 35 | |
---|
33 | | -static const struct drm_encoder_funcs drm_simple_kms_encoder_funcs = { |
---|
| 36 | +static const struct drm_encoder_funcs drm_simple_encoder_funcs_cleanup = { |
---|
34 | 37 | .destroy = drm_encoder_cleanup, |
---|
35 | 38 | }; |
---|
| 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); |
---|
36 | 73 | |
---|
37 | 74 | static enum drm_mode_status |
---|
38 | 75 | drm_simple_kms_crtc_mode_valid(struct drm_crtc *crtc, |
---|
.. | .. |
---|
45 | 82 | /* Anything goes */ |
---|
46 | 83 | return MODE_OK; |
---|
47 | 84 | |
---|
48 | | - return pipe->funcs->mode_valid(crtc, mode); |
---|
| 85 | + return pipe->funcs->mode_valid(pipe, mode); |
---|
49 | 86 | } |
---|
50 | 87 | |
---|
51 | 88 | static int drm_simple_kms_crtc_check(struct drm_crtc *crtc, |
---|
.. | .. |
---|
190 | 227 | pipe->funcs->cleanup_fb(pipe, state); |
---|
191 | 228 | } |
---|
192 | 229 | |
---|
| 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 | + |
---|
193 | 237 | static const struct drm_plane_helper_funcs drm_simple_kms_plane_helper_funcs = { |
---|
194 | 238 | .prepare_fb = drm_simple_kms_plane_prepare_fb, |
---|
195 | 239 | .cleanup_fb = drm_simple_kms_plane_cleanup_fb, |
---|
.. | .. |
---|
204 | 248 | .reset = drm_atomic_helper_plane_reset, |
---|
205 | 249 | .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, |
---|
206 | 250 | .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, |
---|
| 251 | + .format_mod_supported = drm_simple_kms_format_mod_supported, |
---|
207 | 252 | }; |
---|
208 | 253 | |
---|
209 | 254 | /** |
---|
.. | .. |
---|
223 | 268 | int drm_simple_display_pipe_attach_bridge(struct drm_simple_display_pipe *pipe, |
---|
224 | 269 | struct drm_bridge *bridge) |
---|
225 | 270 | { |
---|
226 | | - return drm_bridge_attach(&pipe->encoder, bridge, NULL); |
---|
| 271 | + return drm_bridge_attach(&pipe->encoder, bridge, NULL, 0); |
---|
227 | 272 | } |
---|
228 | 273 | EXPORT_SYMBOL(drm_simple_display_pipe_attach_bridge); |
---|
229 | 274 | |
---|
.. | .. |
---|
282 | 327 | return ret; |
---|
283 | 328 | |
---|
284 | 329 | 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); |
---|
287 | 331 | if (ret || !connector) |
---|
288 | 332 | return ret; |
---|
289 | 333 | |
---|