rcar_du_lvds.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * rcar_du_lvds.c -- R-Car Display Unit LVDS Encoder
  3. *
  4. * Copyright (C) 2013 Renesas 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_crtc.h>
  15. #include <drm/drm_crtc_helper.h>
  16. #include "rcar_du_drv.h"
  17. #include "rcar_du_kms.h"
  18. #include "rcar_du_lvds.h"
  19. #include "rcar_du_lvdscon.h"
  20. static void rcar_du_lvds_encoder_dpms(struct drm_encoder *encoder, int mode)
  21. {
  22. }
  23. static bool rcar_du_lvds_encoder_mode_fixup(struct drm_encoder *encoder,
  24. const struct drm_display_mode *mode,
  25. struct drm_display_mode *adjusted_mode)
  26. {
  27. const struct drm_display_mode *panel_mode;
  28. struct drm_device *dev = encoder->dev;
  29. struct drm_connector *connector;
  30. bool found = false;
  31. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  32. if (connector->encoder == encoder) {
  33. found = true;
  34. break;
  35. }
  36. }
  37. if (!found) {
  38. dev_dbg(dev->dev, "mode_fixup: no connector found\n");
  39. return false;
  40. }
  41. if (list_empty(&connector->modes)) {
  42. dev_dbg(dev->dev, "mode_fixup: empty modes list\n");
  43. return false;
  44. }
  45. panel_mode = list_first_entry(&connector->modes,
  46. struct drm_display_mode, head);
  47. /* We're not allowed to modify the resolution. */
  48. if (mode->hdisplay != panel_mode->hdisplay ||
  49. mode->vdisplay != panel_mode->vdisplay)
  50. return false;
  51. /* The flat panel mode is fixed, just copy it to the adjusted mode. */
  52. drm_mode_copy(adjusted_mode, panel_mode);
  53. return true;
  54. }
  55. static const struct drm_encoder_helper_funcs encoder_helper_funcs = {
  56. .dpms = rcar_du_lvds_encoder_dpms,
  57. .mode_fixup = rcar_du_lvds_encoder_mode_fixup,
  58. .prepare = rcar_du_encoder_mode_prepare,
  59. .commit = rcar_du_encoder_mode_commit,
  60. .mode_set = rcar_du_encoder_mode_set,
  61. };
  62. static const struct drm_encoder_funcs encoder_funcs = {
  63. .destroy = drm_encoder_cleanup,
  64. };
  65. int rcar_du_lvds_init(struct rcar_du_device *rcdu,
  66. const struct rcar_du_encoder_lvds_data *data,
  67. unsigned int output)
  68. {
  69. struct rcar_du_encoder *renc;
  70. int ret;
  71. renc = devm_kzalloc(rcdu->dev, sizeof(*renc), GFP_KERNEL);
  72. if (renc == NULL)
  73. return -ENOMEM;
  74. renc->output = output;
  75. ret = drm_encoder_init(rcdu->ddev, &renc->encoder, &encoder_funcs,
  76. DRM_MODE_ENCODER_LVDS);
  77. if (ret < 0)
  78. return ret;
  79. drm_encoder_helper_add(&renc->encoder, &encoder_helper_funcs);
  80. return rcar_du_lvds_connector_init(rcdu, renc, &data->panel);
  81. }