1 // SPDX-License-Identifier: GPL-2.0
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
10 #include <drm/drm_crtc_helper.h>
11 #include <drm/drm_atomic_helper.h>
13 static void vkms_connector_destroy(struct drm_connector *connector)
15 drm_connector_unregister(connector);
16 drm_connector_cleanup(connector);
19 static const struct drm_connector_funcs vkms_connector_funcs = {
20 .fill_modes = drm_helper_probe_single_connector_modes,
21 .destroy = vkms_connector_destroy,
22 .reset = drm_atomic_helper_connector_reset,
23 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
24 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
27 static const struct drm_encoder_funcs vkms_encoder_funcs = {
28 .destroy = drm_encoder_cleanup,
31 static int vkms_conn_get_modes(struct drm_connector *connector)
35 count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
36 drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
41 static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
42 .get_modes = vkms_conn_get_modes,
45 int vkms_output_init(struct vkms_device *vkmsdev)
47 struct vkms_output *output = &vkmsdev->output;
48 struct drm_device *dev = &vkmsdev->drm;
49 struct drm_connector *connector = &output->connector;
50 struct drm_encoder *encoder = &output->encoder;
51 struct drm_crtc *crtc = &output->crtc;
52 struct drm_plane *primary, *cursor = NULL;
55 primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY);
57 return PTR_ERR(primary);
60 cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR);
62 ret = PTR_ERR(cursor);
67 ret = vkms_crtc_init(dev, crtc, primary, cursor);
71 ret = drm_connector_init(dev, connector, &vkms_connector_funcs,
72 DRM_MODE_CONNECTOR_VIRTUAL);
74 DRM_ERROR("Failed to init connector\n");
78 drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
80 ret = drm_connector_register(connector);
82 DRM_ERROR("Failed to register connector\n");
83 goto err_connector_register;
86 ret = drm_encoder_init(dev, encoder, &vkms_encoder_funcs,
87 DRM_MODE_ENCODER_VIRTUAL, NULL);
89 DRM_ERROR("Failed to init encoder\n");
92 encoder->possible_crtcs = 1;
94 ret = drm_connector_attach_encoder(connector, encoder);
96 DRM_ERROR("Failed to attach connector to encoder\n");
100 drm_mode_config_reset(dev);
105 drm_encoder_cleanup(encoder);
108 drm_connector_unregister(connector);
110 err_connector_register:
111 drm_connector_cleanup(connector);
114 drm_crtc_cleanup(crtc);
118 drm_plane_cleanup(cursor);
121 drm_plane_cleanup(primary);