rcar_du_lvdscon.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * rcar_du_lvdscon.c -- R-Car Display Unit LVDS Connector
  3. *
  4. * Copyright (C) 2013-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 <video/display_timing.h>
  18. #include <video/of_display_timing.h>
  19. #include <video/videomode.h>
  20. #include "rcar_du_drv.h"
  21. #include "rcar_du_encoder.h"
  22. #include "rcar_du_kms.h"
  23. #include "rcar_du_lvdscon.h"
  24. struct rcar_du_lvds_connector {
  25. struct rcar_du_connector connector;
  26. struct {
  27. unsigned int width_mm; /* Panel width in mm */
  28. unsigned int height_mm; /* Panel height in mm */
  29. struct videomode mode;
  30. } panel;
  31. };
  32. #define to_rcar_lvds_connector(c) \
  33. container_of(c, struct rcar_du_lvds_connector, connector.connector)
  34. static int rcar_du_lvds_connector_get_modes(struct drm_connector *connector)
  35. {
  36. struct rcar_du_lvds_connector *lvdscon =
  37. to_rcar_lvds_connector(connector);
  38. struct drm_display_mode *mode;
  39. mode = drm_mode_create(connector->dev);
  40. if (mode == NULL)
  41. return 0;
  42. mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
  43. drm_display_mode_from_videomode(&lvdscon->panel.mode, mode);
  44. drm_mode_probed_add(connector, mode);
  45. return 1;
  46. }
  47. static const struct drm_connector_helper_funcs connector_helper_funcs = {
  48. .get_modes = rcar_du_lvds_connector_get_modes,
  49. .best_encoder = rcar_du_connector_best_encoder,
  50. };
  51. static enum drm_connector_status
  52. rcar_du_lvds_connector_detect(struct drm_connector *connector, bool force)
  53. {
  54. return connector_status_connected;
  55. }
  56. static const struct drm_connector_funcs connector_funcs = {
  57. .dpms = drm_atomic_helper_connector_dpms,
  58. .reset = drm_atomic_helper_connector_reset,
  59. .detect = rcar_du_lvds_connector_detect,
  60. .fill_modes = drm_helper_probe_single_connector_modes,
  61. .destroy = drm_connector_cleanup,
  62. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  63. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  64. };
  65. int rcar_du_lvds_connector_init(struct rcar_du_device *rcdu,
  66. struct rcar_du_encoder *renc,
  67. /* TODO const */ struct device_node *np)
  68. {
  69. struct drm_encoder *encoder = rcar_encoder_to_drm_encoder(renc);
  70. struct rcar_du_lvds_connector *lvdscon;
  71. struct drm_connector *connector;
  72. struct display_timing timing;
  73. int ret;
  74. lvdscon = devm_kzalloc(rcdu->dev, sizeof(*lvdscon), GFP_KERNEL);
  75. if (lvdscon == NULL)
  76. return -ENOMEM;
  77. ret = of_get_display_timing(np, "panel-timing", &timing);
  78. if (ret < 0)
  79. return ret;
  80. videomode_from_timing(&timing, &lvdscon->panel.mode);
  81. of_property_read_u32(np, "width-mm", &lvdscon->panel.width_mm);
  82. of_property_read_u32(np, "height-mm", &lvdscon->panel.height_mm);
  83. connector = &lvdscon->connector.connector;
  84. connector->display_info.width_mm = lvdscon->panel.width_mm;
  85. connector->display_info.height_mm = lvdscon->panel.height_mm;
  86. ret = drm_connector_init(rcdu->ddev, connector, &connector_funcs,
  87. DRM_MODE_CONNECTOR_LVDS);
  88. if (ret < 0)
  89. return ret;
  90. drm_connector_helper_add(connector, &connector_helper_funcs);
  91. connector->dpms = DRM_MODE_DPMS_OFF;
  92. drm_object_property_set_value(&connector->base,
  93. rcdu->ddev->mode_config.dpms_property, DRM_MODE_DPMS_OFF);
  94. ret = drm_mode_connector_attach_encoder(connector, encoder);
  95. if (ret < 0)
  96. return ret;
  97. lvdscon->connector.encoder = renc;
  98. return 0;
  99. }