drm_client_setup.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // SPDX-License-Identifier: MIT
  2. #include <linux/export.h>
  3. #include <drm/clients/drm_client_setup.h>
  4. #include <drm/drm_device.h>
  5. #include <drm/drm_drv.h>
  6. #include <drm/drm_fourcc.h>
  7. #include <drm/drm_print.h>
  8. #include "drm_client_internal.h"
  9. static char drm_client_default[16] = CONFIG_DRM_CLIENT_DEFAULT;
  10. module_param_string(active, drm_client_default, sizeof(drm_client_default), 0444);
  11. MODULE_PARM_DESC(active,
  12. "Choose which drm client to start, default is "
  13. CONFIG_DRM_CLIENT_DEFAULT);
  14. /**
  15. * drm_client_setup() - Setup in-kernel DRM clients
  16. * @dev: DRM device
  17. * @format: Preferred pixel format for the device. Use NULL, unless
  18. * there is clearly a driver-preferred format.
  19. *
  20. * This function sets up the in-kernel DRM clients. Restore, hotplug
  21. * events and teardown are all taken care of.
  22. *
  23. * Drivers should call drm_client_setup() after registering the new
  24. * DRM device with drm_dev_register(). This function is safe to call
  25. * even when there are no connectors present. Setup will be retried
  26. * on the next hotplug event.
  27. *
  28. * The clients are destroyed by drm_dev_unregister().
  29. */
  30. void drm_client_setup(struct drm_device *dev, const struct drm_format_info *format)
  31. {
  32. if (!drm_core_check_feature(dev, DRIVER_MODESET)) {
  33. drm_dbg(dev, "driver does not support mode-setting, skipping DRM clients\n");
  34. return;
  35. }
  36. #ifdef CONFIG_DRM_FBDEV_EMULATION
  37. if (!strcmp(drm_client_default, "fbdev")) {
  38. int ret;
  39. ret = drm_fbdev_client_setup(dev, format);
  40. if (ret)
  41. drm_warn(dev, "Failed to set up DRM client; error %d\n", ret);
  42. return;
  43. }
  44. #endif
  45. #ifdef CONFIG_DRM_CLIENT_LOG
  46. if (!strcmp(drm_client_default, "log")) {
  47. drm_log_register(dev);
  48. return;
  49. }
  50. #endif
  51. if (strcmp(drm_client_default, ""))
  52. drm_warn(dev, "Unknown DRM client %s\n", drm_client_default);
  53. }
  54. EXPORT_SYMBOL(drm_client_setup);
  55. /**
  56. * drm_client_setup_with_fourcc() - Setup in-kernel DRM clients for color mode
  57. * @dev: DRM device
  58. * @fourcc: Preferred pixel format as 4CC code for the device
  59. *
  60. * This function sets up the in-kernel DRM clients. It is equivalent
  61. * to drm_client_setup(), but expects a 4CC code as second argument.
  62. */
  63. void drm_client_setup_with_fourcc(struct drm_device *dev, u32 fourcc)
  64. {
  65. drm_client_setup(dev, drm_format_info(fourcc));
  66. }
  67. EXPORT_SYMBOL(drm_client_setup_with_fourcc);
  68. /**
  69. * drm_client_setup_with_color_mode() - Setup in-kernel DRM clients for color mode
  70. * @dev: DRM device
  71. * @color_mode: Preferred color mode for the device
  72. *
  73. * This function sets up the in-kernel DRM clients. It is equivalent
  74. * to drm_client_setup(), but expects a color mode as second argument.
  75. *
  76. * Do not use this function in new drivers. Prefer drm_client_setup() with a
  77. * format of NULL.
  78. */
  79. void drm_client_setup_with_color_mode(struct drm_device *dev, unsigned int color_mode)
  80. {
  81. u32 fourcc = drm_driver_color_mode_format(dev, color_mode);
  82. drm_client_setup_with_fourcc(dev, fourcc);
  83. }
  84. EXPORT_SYMBOL(drm_client_setup_with_color_mode);
  85. MODULE_DESCRIPTION("In-kernel DRM clients");
  86. MODULE_LICENSE("GPL and additional rights");