edp_bridge.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include "edp.h"
  14. struct edp_bridge {
  15. struct drm_bridge base;
  16. struct msm_edp *edp;
  17. };
  18. #define to_edp_bridge(x) container_of(x, struct edp_bridge, base)
  19. void edp_bridge_destroy(struct drm_bridge *bridge)
  20. {
  21. }
  22. static void edp_bridge_pre_enable(struct drm_bridge *bridge)
  23. {
  24. struct edp_bridge *edp_bridge = to_edp_bridge(bridge);
  25. struct msm_edp *edp = edp_bridge->edp;
  26. DBG("");
  27. msm_edp_ctrl_power(edp->ctrl, true);
  28. }
  29. static void edp_bridge_enable(struct drm_bridge *bridge)
  30. {
  31. DBG("");
  32. }
  33. static void edp_bridge_disable(struct drm_bridge *bridge)
  34. {
  35. DBG("");
  36. }
  37. static void edp_bridge_post_disable(struct drm_bridge *bridge)
  38. {
  39. struct edp_bridge *edp_bridge = to_edp_bridge(bridge);
  40. struct msm_edp *edp = edp_bridge->edp;
  41. DBG("");
  42. msm_edp_ctrl_power(edp->ctrl, false);
  43. }
  44. static void edp_bridge_mode_set(struct drm_bridge *bridge,
  45. struct drm_display_mode *mode,
  46. struct drm_display_mode *adjusted_mode)
  47. {
  48. struct drm_device *dev = bridge->dev;
  49. struct drm_connector *connector;
  50. struct edp_bridge *edp_bridge = to_edp_bridge(bridge);
  51. struct msm_edp *edp = edp_bridge->edp;
  52. DBG("set mode: %d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
  53. mode->base.id, mode->name,
  54. mode->vrefresh, mode->clock,
  55. mode->hdisplay, mode->hsync_start,
  56. mode->hsync_end, mode->htotal,
  57. mode->vdisplay, mode->vsync_start,
  58. mode->vsync_end, mode->vtotal,
  59. mode->type, mode->flags);
  60. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  61. if ((connector->encoder != NULL) &&
  62. (connector->encoder->bridge == bridge)) {
  63. msm_edp_ctrl_timing_cfg(edp->ctrl,
  64. adjusted_mode, &connector->display_info);
  65. break;
  66. }
  67. }
  68. }
  69. static const struct drm_bridge_funcs edp_bridge_funcs = {
  70. .pre_enable = edp_bridge_pre_enable,
  71. .enable = edp_bridge_enable,
  72. .disable = edp_bridge_disable,
  73. .post_disable = edp_bridge_post_disable,
  74. .mode_set = edp_bridge_mode_set,
  75. };
  76. /* initialize bridge */
  77. struct drm_bridge *msm_edp_bridge_init(struct msm_edp *edp)
  78. {
  79. struct drm_bridge *bridge = NULL;
  80. struct edp_bridge *edp_bridge;
  81. int ret;
  82. edp_bridge = devm_kzalloc(edp->dev->dev,
  83. sizeof(*edp_bridge), GFP_KERNEL);
  84. if (!edp_bridge) {
  85. ret = -ENOMEM;
  86. goto fail;
  87. }
  88. edp_bridge->edp = edp;
  89. bridge = &edp_bridge->base;
  90. bridge->funcs = &edp_bridge_funcs;
  91. ret = drm_bridge_attach(edp->dev, bridge);
  92. if (ret)
  93. goto fail;
  94. return bridge;
  95. fail:
  96. if (bridge)
  97. edp_bridge_destroy(bridge);
  98. return ERR_PTR(ret);
  99. }