tidss_encoder.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
  4. * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  5. */
  6. #include <linux/export.h>
  7. #include <drm/drmP.h>
  8. #include <drm/drm_crtc.h>
  9. #include <drm/drm_crtc_helper.h>
  10. #include <drm/drm_panel.h>
  11. #include <drm/drm_of.h>
  12. #include "tidss_drv.h"
  13. #include "tidss_encoder.h"
  14. #include "tidss_crtc.h"
  15. /* -----------------------------------------------------------------------------
  16. * Encoder
  17. */
  18. static int tidss_encoder_atomic_check(struct drm_encoder *encoder,
  19. struct drm_crtc_state *crtc_state,
  20. struct drm_connector_state *conn_state)
  21. {
  22. struct drm_device *ddev = encoder->dev;
  23. struct tidss_crtc_state *tcrtc_state = to_tidss_crtc_state(crtc_state);
  24. struct drm_display_info *di = &conn_state->connector->display_info;
  25. dev_dbg(ddev->dev, "%s\n", __func__);
  26. if (!di->bus_formats || di->num_bus_formats == 0) {
  27. dev_err(ddev->dev, "%s: No bus_formats in connected display\n",
  28. __func__);
  29. return -EINVAL;
  30. }
  31. // XXX any cleaner way to set bus format and flags?
  32. tcrtc_state->bus_format = di->bus_formats[0];
  33. tcrtc_state->bus_flags = di->bus_flags;
  34. return 0;
  35. }
  36. static const struct drm_encoder_helper_funcs encoder_helper_funcs = {
  37. .atomic_check = tidss_encoder_atomic_check,
  38. };
  39. static const struct drm_encoder_funcs encoder_funcs = {
  40. .destroy = drm_encoder_cleanup,
  41. };
  42. struct drm_encoder *tidss_encoder_create(struct tidss_device *tidss,
  43. u32 encoder_type, u32 possible_crtcs)
  44. {
  45. struct drm_encoder *enc;
  46. int ret;
  47. enc = devm_kzalloc(tidss->dev, sizeof(*enc), GFP_KERNEL);
  48. if (!enc)
  49. return ERR_PTR(-ENOMEM);
  50. enc->possible_crtcs = possible_crtcs;
  51. ret = drm_encoder_init(tidss->ddev, enc, &encoder_funcs,
  52. encoder_type, NULL);
  53. if (ret < 0)
  54. return ERR_PTR(ret);
  55. drm_encoder_helper_add(enc, &encoder_helper_funcs);
  56. dev_dbg(tidss->dev, "Encoder create done\n");
  57. return enc;
  58. }