vc4_kms.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (C) 2015 Broadcom
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. /**
  9. * DOC: VC4 KMS
  10. *
  11. * This is the general code for implementing KMS mode setting that
  12. * doesn't clearly associate with any of the other objects (plane,
  13. * crtc, HDMI encoder).
  14. */
  15. #include "drm_crtc.h"
  16. #include "drm_atomic_helper.h"
  17. #include "drm_crtc_helper.h"
  18. #include "drm_plane_helper.h"
  19. #include "drm_fb_cma_helper.h"
  20. #include "vc4_drv.h"
  21. static void vc4_output_poll_changed(struct drm_device *dev)
  22. {
  23. struct vc4_dev *vc4 = to_vc4_dev(dev);
  24. if (vc4->fbdev)
  25. drm_fbdev_cma_hotplug_event(vc4->fbdev);
  26. }
  27. static const struct drm_mode_config_funcs vc4_mode_funcs = {
  28. .output_poll_changed = vc4_output_poll_changed,
  29. .atomic_check = drm_atomic_helper_check,
  30. .atomic_commit = drm_atomic_helper_commit,
  31. .fb_create = drm_fb_cma_create,
  32. };
  33. int vc4_kms_load(struct drm_device *dev)
  34. {
  35. struct vc4_dev *vc4 = to_vc4_dev(dev);
  36. int ret;
  37. ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
  38. if (ret < 0) {
  39. dev_err(dev->dev, "failed to initialize vblank\n");
  40. return ret;
  41. }
  42. dev->mode_config.max_width = 2048;
  43. dev->mode_config.max_height = 2048;
  44. dev->mode_config.funcs = &vc4_mode_funcs;
  45. dev->mode_config.preferred_depth = 24;
  46. dev->vblank_disable_allowed = true;
  47. drm_mode_config_reset(dev);
  48. vc4->fbdev = drm_fbdev_cma_init(dev, 32,
  49. dev->mode_config.num_crtc,
  50. dev->mode_config.num_connector);
  51. if (IS_ERR(vc4->fbdev))
  52. vc4->fbdev = NULL;
  53. drm_kms_helper_poll_init(dev);
  54. return 0;
  55. }