Linux Audio

Check our new training course

Buildroot integration, development and maintenance

Need a Buildroot system for your embedded project?
Loading...
v6.9.4
  1// SPDX-License-Identifier: GPL-2.0 OR MIT
  2
  3/*
  4 *  Xen para-virtual DRM device
  5 *
  6 * Copyright (C) 2016-2018 EPAM Systems Inc.
  7 *
  8 * Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
  9 */
 10
 11#include <drm/drm_atomic_helper.h>
 12#include <drm/drm_drv.h>
 13#include <drm/drm_fourcc.h>
 14#include <drm/drm_probe_helper.h>
 15
 16#include <video/videomode.h>
 17
 18#include "xen_drm_front.h"
 19#include "xen_drm_front_conn.h"
 20#include "xen_drm_front_kms.h"
 21
 22static struct xen_drm_front_drm_pipeline *
 23to_xen_drm_pipeline(struct drm_connector *connector)
 24{
 25	return container_of(connector, struct xen_drm_front_drm_pipeline, conn);
 26}
 27
 28static const u32 plane_formats[] = {
 29	DRM_FORMAT_RGB565,
 30	DRM_FORMAT_RGB888,
 31	DRM_FORMAT_XRGB8888,
 32	DRM_FORMAT_ARGB8888,
 33	DRM_FORMAT_XRGB4444,
 34	DRM_FORMAT_ARGB4444,
 35	DRM_FORMAT_XRGB1555,
 36	DRM_FORMAT_ARGB1555,
 37	DRM_FORMAT_YUYV,
 38};
 39
 40const u32 *xen_drm_front_conn_get_formats(int *format_count)
 41{
 42	*format_count = ARRAY_SIZE(plane_formats);
 43	return plane_formats;
 44}
 45
 46static int connector_detect(struct drm_connector *connector,
 47			    struct drm_modeset_acquire_ctx *ctx,
 48			    bool force)
 49{
 50	struct xen_drm_front_drm_pipeline *pipeline =
 51			to_xen_drm_pipeline(connector);
 52
 53	if (drm_dev_is_unplugged(connector->dev))
 54		pipeline->conn_connected = false;
 55
 56	return pipeline->conn_connected ? connector_status_connected :
 57			connector_status_disconnected;
 58}
 59
 60#define XEN_DRM_CRTC_VREFRESH_HZ	60
 61
 62static int connector_get_modes(struct drm_connector *connector)
 63{
 64	struct xen_drm_front_drm_pipeline *pipeline =
 65			to_xen_drm_pipeline(connector);
 66	struct drm_display_mode *mode;
 67	struct videomode videomode;
 68	int width, height;
 69
 70	mode = drm_mode_create(connector->dev);
 71	if (!mode)
 72		return 0;
 73
 74	memset(&videomode, 0, sizeof(videomode));
 75	videomode.hactive = pipeline->width;
 76	videomode.vactive = pipeline->height;
 77	width = videomode.hactive + videomode.hfront_porch +
 78			videomode.hback_porch + videomode.hsync_len;
 79	height = videomode.vactive + videomode.vfront_porch +
 80			videomode.vback_porch + videomode.vsync_len;
 81	videomode.pixelclock = width * height * XEN_DRM_CRTC_VREFRESH_HZ;
 82	mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
 83
 84	drm_display_mode_from_videomode(&videomode, mode);
 85	drm_mode_probed_add(connector, mode);
 86	return 1;
 87}
 88
 89static const struct drm_connector_helper_funcs connector_helper_funcs = {
 90	.get_modes = connector_get_modes,
 91	.detect_ctx = connector_detect,
 92};
 93
 94static const struct drm_connector_funcs connector_funcs = {
 95	.fill_modes = drm_helper_probe_single_connector_modes,
 96	.destroy = drm_connector_cleanup,
 97	.reset = drm_atomic_helper_connector_reset,
 98	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
 99	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
100};
101
102int xen_drm_front_conn_init(struct xen_drm_front_drm_info *drm_info,
103			    struct drm_connector *connector)
104{
105	struct xen_drm_front_drm_pipeline *pipeline =
106			to_xen_drm_pipeline(connector);
107
108	drm_connector_helper_add(connector, &connector_helper_funcs);
109
110	pipeline->conn_connected = true;
111
112	connector->polled = DRM_CONNECTOR_POLL_CONNECT |
113			DRM_CONNECTOR_POLL_DISCONNECT;
114
115	return drm_connector_init(drm_info->drm_dev, connector,
116				  &connector_funcs, DRM_MODE_CONNECTOR_VIRTUAL);
117}
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0 OR MIT
  2
  3/*
  4 *  Xen para-virtual DRM device
  5 *
  6 * Copyright (C) 2016-2018 EPAM Systems Inc.
  7 *
  8 * Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
  9 */
 10
 11#include <drm/drm_atomic_helper.h>
 12#include <drm/drm_drv.h>
 
 13#include <drm/drm_probe_helper.h>
 14
 15#include <video/videomode.h>
 16
 17#include "xen_drm_front.h"
 18#include "xen_drm_front_conn.h"
 19#include "xen_drm_front_kms.h"
 20
 21static struct xen_drm_front_drm_pipeline *
 22to_xen_drm_pipeline(struct drm_connector *connector)
 23{
 24	return container_of(connector, struct xen_drm_front_drm_pipeline, conn);
 25}
 26
 27static 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,
 36	DRM_FORMAT_YUYV,
 37};
 38
 39const u32 *xen_drm_front_conn_get_formats(int *format_count)
 40{
 41	*format_count = ARRAY_SIZE(plane_formats);
 42	return plane_formats;
 43}
 44
 45static int connector_detect(struct drm_connector *connector,
 46			    struct drm_modeset_acquire_ctx *ctx,
 47			    bool force)
 48{
 49	struct xen_drm_front_drm_pipeline *pipeline =
 50			to_xen_drm_pipeline(connector);
 51
 52	if (drm_dev_is_unplugged(connector->dev))
 53		pipeline->conn_connected = false;
 54
 55	return pipeline->conn_connected ? connector_status_connected :
 56			connector_status_disconnected;
 57}
 58
 59#define XEN_DRM_CRTC_VREFRESH_HZ	60
 60
 61static int connector_get_modes(struct drm_connector *connector)
 62{
 63	struct xen_drm_front_drm_pipeline *pipeline =
 64			to_xen_drm_pipeline(connector);
 65	struct drm_display_mode *mode;
 66	struct videomode videomode;
 67	int width, height;
 68
 69	mode = drm_mode_create(connector->dev);
 70	if (!mode)
 71		return 0;
 72
 73	memset(&videomode, 0, sizeof(videomode));
 74	videomode.hactive = pipeline->width;
 75	videomode.vactive = pipeline->height;
 76	width = videomode.hactive + videomode.hfront_porch +
 77			videomode.hback_porch + videomode.hsync_len;
 78	height = videomode.vactive + videomode.vfront_porch +
 79			videomode.vback_porch + videomode.vsync_len;
 80	videomode.pixelclock = width * height * XEN_DRM_CRTC_VREFRESH_HZ;
 81	mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
 82
 83	drm_display_mode_from_videomode(&videomode, mode);
 84	drm_mode_probed_add(connector, mode);
 85	return 1;
 86}
 87
 88static const struct drm_connector_helper_funcs connector_helper_funcs = {
 89	.get_modes = connector_get_modes,
 90	.detect_ctx = connector_detect,
 91};
 92
 93static const struct drm_connector_funcs connector_funcs = {
 94	.fill_modes = drm_helper_probe_single_connector_modes,
 95	.destroy = drm_connector_cleanup,
 96	.reset = drm_atomic_helper_connector_reset,
 97	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
 98	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
 99};
100
101int xen_drm_front_conn_init(struct xen_drm_front_drm_info *drm_info,
102			    struct drm_connector *connector)
103{
104	struct xen_drm_front_drm_pipeline *pipeline =
105			to_xen_drm_pipeline(connector);
106
107	drm_connector_helper_add(connector, &connector_helper_funcs);
108
109	pipeline->conn_connected = true;
110
111	connector->polled = DRM_CONNECTOR_POLL_CONNECT |
112			DRM_CONNECTOR_POLL_DISCONNECT;
113
114	return drm_connector_init(drm_info->drm_dev, connector,
115				  &connector_funcs, DRM_MODE_CONNECTOR_VIRTUAL);
116}