1 // SPDX-License-Identifier: GPL-2.0+
4 #include <drm/drm_atomic_helper.h>
5 #include <drm/drm_edid.h>
6 #include <drm/drm_probe_helper.h>
7 #include <drm/drm_simple_kms_helper.h>
9 static void vkms_connector_destroy(struct drm_connector *connector)
11 drm_connector_cleanup(connector);
14 static const struct drm_connector_funcs vkms_connector_funcs = {
15 .fill_modes = drm_helper_probe_single_connector_modes,
16 .destroy = vkms_connector_destroy,
17 .reset = drm_atomic_helper_connector_reset,
18 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
19 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
22 static int vkms_conn_get_modes(struct drm_connector *connector)
26 count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
27 drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
32 static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
33 .get_modes = vkms_conn_get_modes,
36 static int vkms_add_overlay_plane(struct vkms_device *vkmsdev, int index,
37 struct drm_crtc *crtc)
39 struct vkms_plane *overlay;
41 overlay = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_OVERLAY, index);
43 return PTR_ERR(overlay);
45 if (!overlay->base.possible_crtcs)
46 overlay->base.possible_crtcs = drm_crtc_mask(crtc);
51 int vkms_output_init(struct vkms_device *vkmsdev, int index)
53 struct vkms_output *output = &vkmsdev->output;
54 struct drm_device *dev = &vkmsdev->drm;
55 struct drm_connector *connector = &output->connector;
56 struct drm_encoder *encoder = &output->encoder;
57 struct drm_crtc *crtc = &output->crtc;
58 struct vkms_plane *primary, *cursor = NULL;
63 primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
65 return PTR_ERR(primary);
67 if (vkmsdev->config->overlay) {
68 for (n = 0; n < NUM_OVERLAY_PLANES; n++) {
69 ret = vkms_add_overlay_plane(vkmsdev, index, crtc);
75 if (vkmsdev->config->cursor) {
76 cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index);
78 return PTR_ERR(cursor);
81 ret = vkms_crtc_init(dev, crtc, &primary->base, &cursor->base);
85 ret = drm_connector_init(dev, connector, &vkms_connector_funcs,
86 DRM_MODE_CONNECTOR_VIRTUAL);
88 DRM_ERROR("Failed to init connector\n");
92 drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
94 ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_VIRTUAL);
96 DRM_ERROR("Failed to init encoder\n");
99 encoder->possible_crtcs = 1;
101 ret = drm_connector_attach_encoder(connector, encoder);
103 DRM_ERROR("Failed to attach connector to encoder\n");
107 if (vkmsdev->config->writeback) {
108 writeback = vkms_enable_writeback_connector(vkmsdev);
110 DRM_ERROR("Failed to init writeback connector\n");
113 drm_mode_config_reset(dev);
118 drm_encoder_cleanup(encoder);
121 drm_connector_cleanup(connector);
124 drm_crtc_cleanup(crtc);