fsl_dcu_drm_rgb.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright 2015 Freescale Semiconductor, Inc.
  3. *
  4. * Freescale DCU drm device driver
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/backlight.h>
  12. #include <drm/drmP.h>
  13. #include <drm/drm_atomic_helper.h>
  14. #include <drm/drm_crtc_helper.h>
  15. #include <drm/drm_panel.h>
  16. #include "fsl_dcu_drm_drv.h"
  17. static int
  18. fsl_dcu_drm_encoder_atomic_check(struct drm_encoder *encoder,
  19. struct drm_crtc_state *crtc_state,
  20. struct drm_connector_state *conn_state)
  21. {
  22. return 0;
  23. }
  24. static void fsl_dcu_drm_encoder_disable(struct drm_encoder *encoder)
  25. {
  26. }
  27. static void fsl_dcu_drm_encoder_enable(struct drm_encoder *encoder)
  28. {
  29. }
  30. static const struct drm_encoder_helper_funcs encoder_helper_funcs = {
  31. .atomic_check = fsl_dcu_drm_encoder_atomic_check,
  32. .disable = fsl_dcu_drm_encoder_disable,
  33. .enable = fsl_dcu_drm_encoder_enable,
  34. };
  35. static void fsl_dcu_drm_encoder_destroy(struct drm_encoder *encoder)
  36. {
  37. drm_encoder_cleanup(encoder);
  38. }
  39. static const struct drm_encoder_funcs encoder_funcs = {
  40. .destroy = fsl_dcu_drm_encoder_destroy,
  41. };
  42. int fsl_dcu_drm_encoder_create(struct fsl_dcu_drm_device *fsl_dev,
  43. struct drm_crtc *crtc)
  44. {
  45. struct drm_encoder *encoder = &fsl_dev->encoder;
  46. int ret;
  47. encoder->possible_crtcs = 1;
  48. ret = drm_encoder_init(fsl_dev->drm, encoder, &encoder_funcs,
  49. DRM_MODE_ENCODER_LVDS);
  50. if (ret < 0)
  51. return ret;
  52. drm_encoder_helper_add(encoder, &encoder_helper_funcs);
  53. return 0;
  54. }
  55. static void fsl_dcu_drm_connector_destroy(struct drm_connector *connector)
  56. {
  57. drm_connector_unregister(connector);
  58. drm_connector_cleanup(connector);
  59. }
  60. static enum drm_connector_status
  61. fsl_dcu_drm_connector_detect(struct drm_connector *connector, bool force)
  62. {
  63. return connector_status_connected;
  64. }
  65. static const struct drm_connector_funcs fsl_dcu_drm_connector_funcs = {
  66. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  67. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  68. .destroy = fsl_dcu_drm_connector_destroy,
  69. .detect = fsl_dcu_drm_connector_detect,
  70. .dpms = drm_atomic_helper_connector_dpms,
  71. .fill_modes = drm_helper_probe_single_connector_modes,
  72. .reset = drm_atomic_helper_connector_reset,
  73. };
  74. static struct drm_encoder *
  75. fsl_dcu_drm_connector_best_encoder(struct drm_connector *connector)
  76. {
  77. struct fsl_dcu_drm_connector *fsl_con = to_fsl_dcu_connector(connector);
  78. return fsl_con->encoder;
  79. }
  80. static int fsl_dcu_drm_connector_get_modes(struct drm_connector *connector)
  81. {
  82. struct fsl_dcu_drm_connector *fsl_connector;
  83. int (*get_modes)(struct drm_panel *panel);
  84. int num_modes = 0;
  85. fsl_connector = to_fsl_dcu_connector(connector);
  86. if (fsl_connector->panel && fsl_connector->panel->funcs &&
  87. fsl_connector->panel->funcs->get_modes) {
  88. get_modes = fsl_connector->panel->funcs->get_modes;
  89. num_modes = get_modes(fsl_connector->panel);
  90. }
  91. return num_modes;
  92. }
  93. static int fsl_dcu_drm_connector_mode_valid(struct drm_connector *connector,
  94. struct drm_display_mode *mode)
  95. {
  96. if (mode->hdisplay & 0xf)
  97. return MODE_ERROR;
  98. return MODE_OK;
  99. }
  100. static const struct drm_connector_helper_funcs connector_helper_funcs = {
  101. .best_encoder = fsl_dcu_drm_connector_best_encoder,
  102. .get_modes = fsl_dcu_drm_connector_get_modes,
  103. .mode_valid = fsl_dcu_drm_connector_mode_valid,
  104. };
  105. int fsl_dcu_drm_connector_create(struct fsl_dcu_drm_device *fsl_dev,
  106. struct drm_encoder *encoder)
  107. {
  108. struct drm_connector *connector = &fsl_dev->connector.base;
  109. struct drm_mode_config mode_config = fsl_dev->drm->mode_config;
  110. struct device_node *panel_node;
  111. int ret;
  112. fsl_dev->connector.encoder = encoder;
  113. ret = drm_connector_init(fsl_dev->drm, connector,
  114. &fsl_dcu_drm_connector_funcs,
  115. DRM_MODE_CONNECTOR_LVDS);
  116. if (ret < 0)
  117. return ret;
  118. drm_connector_helper_add(connector, &connector_helper_funcs);
  119. ret = drm_connector_register(connector);
  120. if (ret < 0)
  121. goto err_cleanup;
  122. ret = drm_mode_connector_attach_encoder(connector, encoder);
  123. if (ret < 0)
  124. goto err_sysfs;
  125. drm_object_property_set_value(&connector->base,
  126. mode_config.dpms_property,
  127. DRM_MODE_DPMS_OFF);
  128. panel_node = of_parse_phandle(fsl_dev->np, "fsl,panel", 0);
  129. if (panel_node) {
  130. fsl_dev->connector.panel = of_drm_find_panel(panel_node);
  131. if (!fsl_dev->connector.panel) {
  132. ret = -EPROBE_DEFER;
  133. goto err_sysfs;
  134. }
  135. of_node_put(panel_node);
  136. }
  137. ret = drm_panel_attach(fsl_dev->connector.panel, connector);
  138. if (ret) {
  139. dev_err(fsl_dev->dev, "failed to attach panel\n");
  140. goto err_sysfs;
  141. }
  142. return 0;
  143. err_sysfs:
  144. drm_connector_unregister(connector);
  145. err_cleanup:
  146. drm_connector_cleanup(connector);
  147. return ret;
  148. }