xen_drm_front_conn.c 3.2 KB

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