logicvc_mode.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2019-2022 Bootlin
  4. * Author: Paul Kocialkowski <[email protected]>
  5. */
  6. #include <linux/types.h>
  7. #include <drm/drm_atomic.h>
  8. #include <drm/drm_atomic_helper.h>
  9. #include <drm/drm_crtc_helper.h>
  10. #include <drm/drm_drv.h>
  11. #include <drm/drm_fb_helper.h>
  12. #include <drm/drm_gem_dma_helper.h>
  13. #include <drm/drm_gem_framebuffer_helper.h>
  14. #include <drm/drm_mode_config.h>
  15. #include <drm/drm_panel.h>
  16. #include <drm/drm_print.h>
  17. #include <drm/drm_probe_helper.h>
  18. #include <drm/drm_vblank.h>
  19. #include "logicvc_drm.h"
  20. #include "logicvc_interface.h"
  21. #include "logicvc_layer.h"
  22. #include "logicvc_mode.h"
  23. static const struct drm_mode_config_funcs logicvc_mode_config_funcs = {
  24. .fb_create = drm_gem_fb_create,
  25. .output_poll_changed = drm_fb_helper_output_poll_changed,
  26. .atomic_check = drm_atomic_helper_check,
  27. .atomic_commit = drm_atomic_helper_commit,
  28. };
  29. int logicvc_mode_init(struct logicvc_drm *logicvc)
  30. {
  31. struct drm_device *drm_dev = &logicvc->drm_dev;
  32. struct drm_mode_config *mode_config = &drm_dev->mode_config;
  33. struct logicvc_layer *layer_primary;
  34. uint32_t preferred_depth;
  35. int ret;
  36. ret = drm_vblank_init(drm_dev, mode_config->num_crtc);
  37. if (ret) {
  38. drm_err(drm_dev, "Failed to initialize vblank\n");
  39. return ret;
  40. }
  41. layer_primary = logicvc_layer_get_primary(logicvc);
  42. if (!layer_primary) {
  43. drm_err(drm_dev, "Failed to get primary layer\n");
  44. return -EINVAL;
  45. }
  46. preferred_depth = layer_primary->formats->depth;
  47. /* DRM counts alpha in depth, our driver doesn't. */
  48. if (layer_primary->formats->alpha)
  49. preferred_depth += 8;
  50. mode_config->min_width = 64;
  51. mode_config->max_width = 2048;
  52. mode_config->min_height = 1;
  53. mode_config->max_height = 2048;
  54. mode_config->preferred_depth = preferred_depth;
  55. mode_config->funcs = &logicvc_mode_config_funcs;
  56. drm_mode_config_reset(drm_dev);
  57. drm_kms_helper_poll_init(drm_dev);
  58. return 0;
  59. }
  60. void logicvc_mode_fini(struct logicvc_drm *logicvc)
  61. {
  62. struct drm_device *drm_dev = &logicvc->drm_dev;
  63. drm_kms_helper_poll_fini(drm_dev);
  64. }