1 // SPDX-License-Identifier: GPL-2.0+
4 #include <drm/drm_atomic_helper.h>
5 #include <drm/drm_probe_helper.h>
7 static void vkms_connector_destroy(struct drm_connector
*connector
)
9 drm_connector_cleanup(connector
);
12 static const struct drm_connector_funcs vkms_connector_funcs
= {
13 .fill_modes
= drm_helper_probe_single_connector_modes
,
14 .destroy
= vkms_connector_destroy
,
15 .reset
= drm_atomic_helper_connector_reset
,
16 .atomic_duplicate_state
= drm_atomic_helper_connector_duplicate_state
,
17 .atomic_destroy_state
= drm_atomic_helper_connector_destroy_state
,
20 static const struct drm_encoder_funcs vkms_encoder_funcs
= {
21 .destroy
= drm_encoder_cleanup
,
24 static int vkms_conn_get_modes(struct drm_connector
*connector
)
28 count
= drm_add_modes_noedid(connector
, XRES_MAX
, YRES_MAX
);
29 drm_set_preferred_mode(connector
, XRES_DEF
, YRES_DEF
);
34 static const struct drm_connector_helper_funcs vkms_conn_helper_funcs
= {
35 .get_modes
= vkms_conn_get_modes
,
38 int vkms_output_init(struct vkms_device
*vkmsdev
, int index
)
40 struct vkms_output
*output
= &vkmsdev
->output
;
41 struct drm_device
*dev
= &vkmsdev
->drm
;
42 struct drm_connector
*connector
= &output
->connector
;
43 struct drm_encoder
*encoder
= &output
->encoder
;
44 struct drm_crtc
*crtc
= &output
->crtc
;
45 struct drm_plane
*primary
, *cursor
= NULL
;
48 primary
= vkms_plane_init(vkmsdev
, DRM_PLANE_TYPE_PRIMARY
, index
);
50 return PTR_ERR(primary
);
53 cursor
= vkms_plane_init(vkmsdev
, DRM_PLANE_TYPE_CURSOR
, index
);
55 ret
= PTR_ERR(cursor
);
60 ret
= vkms_crtc_init(dev
, crtc
, primary
, cursor
);
64 ret
= drm_connector_init(dev
, connector
, &vkms_connector_funcs
,
65 DRM_MODE_CONNECTOR_VIRTUAL
);
67 DRM_ERROR("Failed to init connector\n");
71 drm_connector_helper_add(connector
, &vkms_conn_helper_funcs
);
73 ret
= drm_encoder_init(dev
, encoder
, &vkms_encoder_funcs
,
74 DRM_MODE_ENCODER_VIRTUAL
, NULL
);
76 DRM_ERROR("Failed to init encoder\n");
79 encoder
->possible_crtcs
= 1;
81 ret
= drm_connector_attach_encoder(connector
, encoder
);
83 DRM_ERROR("Failed to attach connector to encoder\n");
87 drm_mode_config_reset(dev
);
92 drm_encoder_cleanup(encoder
);
95 drm_connector_cleanup(connector
);
98 drm_crtc_cleanup(crtc
);
102 drm_plane_cleanup(cursor
);
105 drm_plane_cleanup(primary
);