2019-02-06 21:01:16 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2018-05-17 06:56:21 +07:00
|
|
|
|
|
|
|
#include "vkms_drv.h"
|
2018-07-12 09:02:14 +07:00
|
|
|
#include <drm/drm_atomic_helper.h>
|
2019-01-18 04:03:34 +07:00
|
|
|
#include <drm/drm_probe_helper.h>
|
2018-05-17 06:56:21 +07:00
|
|
|
|
|
|
|
static void vkms_connector_destroy(struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
drm_connector_cleanup(connector);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_connector_funcs vkms_connector_funcs = {
|
|
|
|
.fill_modes = drm_helper_probe_single_connector_modes,
|
|
|
|
.destroy = vkms_connector_destroy,
|
2018-07-12 09:02:14 +07:00
|
|
|
.reset = drm_atomic_helper_connector_reset,
|
|
|
|
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
|
|
|
|
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
|
2018-05-17 06:56:21 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct drm_encoder_funcs vkms_encoder_funcs = {
|
|
|
|
.destroy = drm_encoder_cleanup,
|
|
|
|
};
|
|
|
|
|
2018-07-12 09:02:14 +07:00
|
|
|
static int vkms_conn_get_modes(struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
|
|
|
|
drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
|
|
|
|
.get_modes = vkms_conn_get_modes,
|
|
|
|
};
|
|
|
|
|
2018-05-17 06:56:21 +07:00
|
|
|
int vkms_output_init(struct vkms_device *vkmsdev)
|
|
|
|
{
|
|
|
|
struct vkms_output *output = &vkmsdev->output;
|
|
|
|
struct drm_device *dev = &vkmsdev->drm;
|
|
|
|
struct drm_connector *connector = &output->connector;
|
|
|
|
struct drm_encoder *encoder = &output->encoder;
|
|
|
|
struct drm_crtc *crtc = &output->crtc;
|
2018-09-06 12:17:16 +07:00
|
|
|
struct drm_plane *primary, *cursor = NULL;
|
2018-05-17 06:56:21 +07:00
|
|
|
int ret;
|
|
|
|
|
2018-09-06 12:17:16 +07:00
|
|
|
primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY);
|
2018-05-17 06:56:21 +07:00
|
|
|
if (IS_ERR(primary))
|
|
|
|
return PTR_ERR(primary);
|
|
|
|
|
2018-09-06 12:19:11 +07:00
|
|
|
if (enable_cursor) {
|
|
|
|
cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR);
|
|
|
|
if (IS_ERR(cursor)) {
|
|
|
|
ret = PTR_ERR(cursor);
|
|
|
|
goto err_cursor;
|
|
|
|
}
|
2018-09-06 12:17:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = vkms_crtc_init(dev, crtc, primary, cursor);
|
2018-05-17 06:56:21 +07:00
|
|
|
if (ret)
|
|
|
|
goto err_crtc;
|
|
|
|
|
|
|
|
ret = drm_connector_init(dev, connector, &vkms_connector_funcs,
|
|
|
|
DRM_MODE_CONNECTOR_VIRTUAL);
|
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("Failed to init connector\n");
|
|
|
|
goto err_connector;
|
|
|
|
}
|
|
|
|
|
2018-07-12 09:02:14 +07:00
|
|
|
drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
|
|
|
|
|
2018-05-17 06:56:21 +07:00
|
|
|
ret = drm_encoder_init(dev, encoder, &vkms_encoder_funcs,
|
|
|
|
DRM_MODE_ENCODER_VIRTUAL, NULL);
|
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("Failed to init encoder\n");
|
|
|
|
goto err_encoder;
|
|
|
|
}
|
|
|
|
encoder->possible_crtcs = 1;
|
|
|
|
|
2018-07-09 15:40:07 +07:00
|
|
|
ret = drm_connector_attach_encoder(connector, encoder);
|
2018-05-17 06:56:21 +07:00
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("Failed to attach connector to encoder\n");
|
|
|
|
goto err_attach;
|
|
|
|
}
|
|
|
|
|
|
|
|
drm_mode_config_reset(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_attach:
|
|
|
|
drm_encoder_cleanup(encoder);
|
|
|
|
|
|
|
|
err_encoder:
|
|
|
|
drm_connector_cleanup(connector);
|
|
|
|
|
|
|
|
err_connector:
|
|
|
|
drm_crtc_cleanup(crtc);
|
|
|
|
|
|
|
|
err_crtc:
|
2018-09-06 12:19:11 +07:00
|
|
|
if (enable_cursor)
|
|
|
|
drm_plane_cleanup(cursor);
|
2018-09-06 12:17:16 +07:00
|
|
|
|
|
|
|
err_cursor:
|
2018-05-17 06:56:21 +07:00
|
|
|
drm_plane_cleanup(primary);
|
2018-09-06 12:17:16 +07:00
|
|
|
|
2018-05-17 06:56:21 +07:00
|
|
|
return ret;
|
|
|
|
}
|