treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / xen / xen_drm_front_conn.c
blob459702fa990e6dfa07c20f75ce567b733cb69bd7
1 // SPDX-License-Identifier: GPL-2.0 OR MIT
3 /*
4 * Xen para-virtual DRM device
6 * Copyright (C) 2016-2018 EPAM Systems Inc.
8 * Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
9 */
11 #include <drm/drm_atomic_helper.h>
12 #include <drm/drm_drv.h>
13 #include <drm/drm_probe_helper.h>
15 #include <video/videomode.h>
17 #include "xen_drm_front.h"
18 #include "xen_drm_front_conn.h"
19 #include "xen_drm_front_kms.h"
21 static struct xen_drm_front_drm_pipeline *
22 to_xen_drm_pipeline(struct drm_connector *connector)
24 return container_of(connector, struct xen_drm_front_drm_pipeline, conn);
27 static const u32 plane_formats[] = {
28 DRM_FORMAT_RGB565,
29 DRM_FORMAT_RGB888,
30 DRM_FORMAT_XRGB8888,
31 DRM_FORMAT_ARGB8888,
32 DRM_FORMAT_XRGB4444,
33 DRM_FORMAT_ARGB4444,
34 DRM_FORMAT_XRGB1555,
35 DRM_FORMAT_ARGB1555,
38 const u32 *xen_drm_front_conn_get_formats(int *format_count)
40 *format_count = ARRAY_SIZE(plane_formats);
41 return plane_formats;
44 static int connector_detect(struct drm_connector *connector,
45 struct drm_modeset_acquire_ctx *ctx,
46 bool force)
48 struct xen_drm_front_drm_pipeline *pipeline =
49 to_xen_drm_pipeline(connector);
51 if (drm_dev_is_unplugged(connector->dev))
52 pipeline->conn_connected = false;
54 return pipeline->conn_connected ? connector_status_connected :
55 connector_status_disconnected;
58 #define XEN_DRM_CRTC_VREFRESH_HZ 60
60 static int connector_get_modes(struct drm_connector *connector)
62 struct xen_drm_front_drm_pipeline *pipeline =
63 to_xen_drm_pipeline(connector);
64 struct drm_display_mode *mode;
65 struct videomode videomode;
66 int width, height;
68 mode = drm_mode_create(connector->dev);
69 if (!mode)
70 return 0;
72 memset(&videomode, 0, sizeof(videomode));
73 videomode.hactive = pipeline->width;
74 videomode.vactive = pipeline->height;
75 width = videomode.hactive + videomode.hfront_porch +
76 videomode.hback_porch + videomode.hsync_len;
77 height = videomode.vactive + videomode.vfront_porch +
78 videomode.vback_porch + videomode.vsync_len;
79 videomode.pixelclock = width * height * XEN_DRM_CRTC_VREFRESH_HZ;
80 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
82 drm_display_mode_from_videomode(&videomode, mode);
83 drm_mode_probed_add(connector, mode);
84 return 1;
87 static const struct drm_connector_helper_funcs connector_helper_funcs = {
88 .get_modes = connector_get_modes,
89 .detect_ctx = connector_detect,
92 static const struct drm_connector_funcs connector_funcs = {
93 .fill_modes = drm_helper_probe_single_connector_modes,
94 .destroy = drm_connector_cleanup,
95 .reset = drm_atomic_helper_connector_reset,
96 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
97 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
100 int xen_drm_front_conn_init(struct xen_drm_front_drm_info *drm_info,
101 struct drm_connector *connector)
103 struct xen_drm_front_drm_pipeline *pipeline =
104 to_xen_drm_pipeline(connector);
106 drm_connector_helper_add(connector, &connector_helper_funcs);
108 pipeline->conn_connected = true;
110 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
111 DRM_CONNECTOR_POLL_DISCONNECT;
113 return drm_connector_init(drm_info->drm_dev, connector,
114 &connector_funcs, DRM_MODE_CONNECTOR_VIRTUAL);