rcar_du_hdmicon.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * R-Car Display Unit HDMI Connector
  3. *
  4. * Copyright (C) 2014 Renesas Electronics Corporation
  5. *
  6. * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <drm/drmP.h>
  14. #include <drm/drm_atomic_helper.h>
  15. #include <drm/drm_crtc.h>
  16. #include <drm/drm_crtc_helper.h>
  17. #include <drm/drm_encoder_slave.h>
  18. #include "rcar_du_drv.h"
  19. #include "rcar_du_encoder.h"
  20. #include "rcar_du_hdmicon.h"
  21. #include "rcar_du_kms.h"
  22. #define to_slave_funcs(e) (to_rcar_encoder(e)->slave.slave_funcs)
  23. static int rcar_du_hdmi_connector_get_modes(struct drm_connector *connector)
  24. {
  25. struct rcar_du_connector *con = to_rcar_connector(connector);
  26. struct drm_encoder *encoder = rcar_encoder_to_drm_encoder(con->encoder);
  27. struct drm_encoder_slave_funcs *sfuncs = to_slave_funcs(encoder);
  28. if (sfuncs->get_modes == NULL)
  29. return 0;
  30. return sfuncs->get_modes(encoder, connector);
  31. }
  32. static int rcar_du_hdmi_connector_mode_valid(struct drm_connector *connector,
  33. struct drm_display_mode *mode)
  34. {
  35. struct rcar_du_connector *con = to_rcar_connector(connector);
  36. struct drm_encoder *encoder = rcar_encoder_to_drm_encoder(con->encoder);
  37. struct drm_encoder_slave_funcs *sfuncs = to_slave_funcs(encoder);
  38. if (sfuncs->mode_valid == NULL)
  39. return MODE_OK;
  40. return sfuncs->mode_valid(encoder, mode);
  41. }
  42. static const struct drm_connector_helper_funcs connector_helper_funcs = {
  43. .get_modes = rcar_du_hdmi_connector_get_modes,
  44. .mode_valid = rcar_du_hdmi_connector_mode_valid,
  45. .best_encoder = rcar_du_connector_best_encoder,
  46. };
  47. static enum drm_connector_status
  48. rcar_du_hdmi_connector_detect(struct drm_connector *connector, bool force)
  49. {
  50. struct rcar_du_connector *con = to_rcar_connector(connector);
  51. struct drm_encoder *encoder = rcar_encoder_to_drm_encoder(con->encoder);
  52. struct drm_encoder_slave_funcs *sfuncs = to_slave_funcs(encoder);
  53. if (sfuncs->detect == NULL)
  54. return connector_status_unknown;
  55. return sfuncs->detect(encoder, connector);
  56. }
  57. static const struct drm_connector_funcs connector_funcs = {
  58. .dpms = drm_atomic_helper_connector_dpms,
  59. .reset = drm_atomic_helper_connector_reset,
  60. .detect = rcar_du_hdmi_connector_detect,
  61. .fill_modes = drm_helper_probe_single_connector_modes,
  62. .destroy = drm_connector_cleanup,
  63. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  64. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  65. };
  66. int rcar_du_hdmi_connector_init(struct rcar_du_device *rcdu,
  67. struct rcar_du_encoder *renc)
  68. {
  69. struct drm_encoder *encoder = rcar_encoder_to_drm_encoder(renc);
  70. struct rcar_du_connector *rcon;
  71. struct drm_connector *connector;
  72. int ret;
  73. rcon = devm_kzalloc(rcdu->dev, sizeof(*rcon), GFP_KERNEL);
  74. if (rcon == NULL)
  75. return -ENOMEM;
  76. connector = &rcon->connector;
  77. connector->display_info.width_mm = 0;
  78. connector->display_info.height_mm = 0;
  79. connector->interlace_allowed = true;
  80. connector->polled = DRM_CONNECTOR_POLL_HPD;
  81. ret = drm_connector_init(rcdu->ddev, connector, &connector_funcs,
  82. DRM_MODE_CONNECTOR_HDMIA);
  83. if (ret < 0)
  84. return ret;
  85. drm_connector_helper_add(connector, &connector_helper_funcs);
  86. connector->dpms = DRM_MODE_DPMS_OFF;
  87. drm_object_property_set_value(&connector->base,
  88. rcdu->ddev->mode_config.dpms_property, DRM_MODE_DPMS_OFF);
  89. ret = drm_mode_connector_attach_encoder(connector, encoder);
  90. if (ret < 0)
  91. return ret;
  92. rcon->encoder = renc;
  93. return 0;
  94. }