Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / vkms / vkms_output.c
blob4a1848b0318fb2ca2af2918d7e967dabe8fdda0b
1 // SPDX-License-Identifier: GPL-2.0+
3 #include "vkms_drv.h"
4 #include <drm/drm_atomic_helper.h>
5 #include <drm/drm_probe_helper.h>
6 #include <drm/drm_simple_kms_helper.h>
8 static void vkms_connector_destroy(struct drm_connector *connector)
10 drm_connector_cleanup(connector);
13 static const struct drm_connector_funcs vkms_connector_funcs = {
14 .fill_modes = drm_helper_probe_single_connector_modes,
15 .destroy = vkms_connector_destroy,
16 .reset = drm_atomic_helper_connector_reset,
17 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
18 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
21 static int vkms_conn_get_modes(struct drm_connector *connector)
23 int count;
25 count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
26 drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
28 return count;
31 static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
32 .get_modes = vkms_conn_get_modes,
35 int vkms_output_init(struct vkms_device *vkmsdev, int index)
37 struct vkms_output *output = &vkmsdev->output;
38 struct drm_device *dev = &vkmsdev->drm;
39 struct drm_connector *connector = &output->connector;
40 struct drm_encoder *encoder = &output->encoder;
41 struct drm_crtc *crtc = &output->crtc;
42 struct drm_plane *primary, *cursor = NULL;
43 int ret;
45 primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
46 if (IS_ERR(primary))
47 return PTR_ERR(primary);
49 if (enable_cursor) {
50 cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index);
51 if (IS_ERR(cursor)) {
52 ret = PTR_ERR(cursor);
53 goto err_cursor;
57 ret = vkms_crtc_init(dev, crtc, primary, cursor);
58 if (ret)
59 goto err_crtc;
61 ret = drm_connector_init(dev, connector, &vkms_connector_funcs,
62 DRM_MODE_CONNECTOR_VIRTUAL);
63 if (ret) {
64 DRM_ERROR("Failed to init connector\n");
65 goto err_connector;
68 drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
70 ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_VIRTUAL);
71 if (ret) {
72 DRM_ERROR("Failed to init encoder\n");
73 goto err_encoder;
75 encoder->possible_crtcs = 1;
77 ret = drm_connector_attach_encoder(connector, encoder);
78 if (ret) {
79 DRM_ERROR("Failed to attach connector to encoder\n");
80 goto err_attach;
83 ret = vkms_enable_writeback_connector(vkmsdev);
84 if (ret)
85 DRM_ERROR("Failed to init writeback connector\n");
87 drm_mode_config_reset(dev);
89 return 0;
91 err_attach:
92 drm_encoder_cleanup(encoder);
94 err_encoder:
95 drm_connector_cleanup(connector);
97 err_connector:
98 drm_crtc_cleanup(crtc);
100 err_crtc:
101 if (enable_cursor)
102 drm_plane_cleanup(cursor);
104 err_cursor:
105 drm_plane_cleanup(primary);
107 return ret;