xen_drm_front_conn.c 3.1 KB

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