tidss_encoder.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
  4. * Author: Tomi Valkeinen <[email protected]>
  5. */
  6. #include <linux/export.h>
  7. #include <drm/drm_crtc.h>
  8. #include <drm/drm_crtc_helper.h>
  9. #include <drm/drm_panel.h>
  10. #include <drm/drm_of.h>
  11. #include "tidss_crtc.h"
  12. #include "tidss_drv.h"
  13. #include "tidss_encoder.h"
  14. static int tidss_encoder_atomic_check(struct drm_encoder *encoder,
  15. struct drm_crtc_state *crtc_state,
  16. struct drm_connector_state *conn_state)
  17. {
  18. struct drm_device *ddev = encoder->dev;
  19. struct tidss_crtc_state *tcrtc_state = to_tidss_crtc_state(crtc_state);
  20. struct drm_display_info *di = &conn_state->connector->display_info;
  21. struct drm_bridge *bridge;
  22. bool bus_flags_set = false;
  23. dev_dbg(ddev->dev, "%s\n", __func__);
  24. /*
  25. * Take the bus_flags from the first bridge that defines
  26. * bridge timings, or from the connector's display_info if no
  27. * bridge defines the timings.
  28. */
  29. drm_for_each_bridge_in_chain(encoder, bridge) {
  30. if (!bridge->timings)
  31. continue;
  32. tcrtc_state->bus_flags = bridge->timings->input_bus_flags;
  33. bus_flags_set = true;
  34. break;
  35. }
  36. if (!di->bus_formats || di->num_bus_formats == 0) {
  37. dev_err(ddev->dev, "%s: No bus_formats in connected display\n",
  38. __func__);
  39. return -EINVAL;
  40. }
  41. // XXX any cleaner way to set bus format and flags?
  42. tcrtc_state->bus_format = di->bus_formats[0];
  43. if (!bus_flags_set)
  44. tcrtc_state->bus_flags = di->bus_flags;
  45. return 0;
  46. }
  47. static void tidss_encoder_destroy(struct drm_encoder *encoder)
  48. {
  49. drm_encoder_cleanup(encoder);
  50. kfree(encoder);
  51. }
  52. static const struct drm_encoder_helper_funcs encoder_helper_funcs = {
  53. .atomic_check = tidss_encoder_atomic_check,
  54. };
  55. static const struct drm_encoder_funcs encoder_funcs = {
  56. .destroy = tidss_encoder_destroy,
  57. };
  58. struct drm_encoder *tidss_encoder_create(struct tidss_device *tidss,
  59. u32 encoder_type, u32 possible_crtcs)
  60. {
  61. struct drm_encoder *enc;
  62. int ret;
  63. enc = kzalloc(sizeof(*enc), GFP_KERNEL);
  64. if (!enc)
  65. return ERR_PTR(-ENOMEM);
  66. enc->possible_crtcs = possible_crtcs;
  67. ret = drm_encoder_init(&tidss->ddev, enc, &encoder_funcs,
  68. encoder_type, NULL);
  69. if (ret < 0) {
  70. kfree(enc);
  71. return ERR_PTR(ret);
  72. }
  73. drm_encoder_helper_add(enc, &encoder_helper_funcs);
  74. dev_dbg(tidss->dev, "Encoder create done\n");
  75. return enc;
  76. }