atmel_hlcdc_output.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2014 Traphandler
  3. * Copyright (C) 2014 Free Electrons
  4. * Copyright (C) 2014 Atmel
  5. *
  6. * Author: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
  7. * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published by
  11. * the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <linux/of_graph.h>
  22. #include <drm/drmP.h>
  23. #include <drm/drm_of.h>
  24. #include <drm/drm_bridge.h>
  25. #include "atmel_hlcdc_dc.h"
  26. static const struct drm_encoder_funcs atmel_hlcdc_panel_encoder_funcs = {
  27. .destroy = drm_encoder_cleanup,
  28. };
  29. static int atmel_hlcdc_attach_endpoint(struct drm_device *dev, int endpoint)
  30. {
  31. struct drm_encoder *encoder;
  32. struct drm_panel *panel;
  33. struct drm_bridge *bridge;
  34. int ret;
  35. ret = drm_of_find_panel_or_bridge(dev->dev->of_node, 0, endpoint,
  36. &panel, &bridge);
  37. if (ret)
  38. return ret;
  39. encoder = devm_kzalloc(dev->dev, sizeof(*encoder), GFP_KERNEL);
  40. if (!encoder)
  41. return -EINVAL;
  42. ret = drm_encoder_init(dev, encoder,
  43. &atmel_hlcdc_panel_encoder_funcs,
  44. DRM_MODE_ENCODER_NONE, NULL);
  45. if (ret)
  46. return ret;
  47. encoder->possible_crtcs = 0x1;
  48. if (panel) {
  49. bridge = drm_panel_bridge_add(panel, DRM_MODE_CONNECTOR_Unknown);
  50. if (IS_ERR(bridge))
  51. return PTR_ERR(bridge);
  52. }
  53. if (bridge) {
  54. ret = drm_bridge_attach(encoder, bridge, NULL);
  55. if (!ret)
  56. return 0;
  57. if (panel)
  58. drm_panel_bridge_remove(bridge);
  59. }
  60. drm_encoder_cleanup(encoder);
  61. return ret;
  62. }
  63. int atmel_hlcdc_create_outputs(struct drm_device *dev)
  64. {
  65. int endpoint, ret = 0;
  66. for (endpoint = 0; !ret; endpoint++)
  67. ret = atmel_hlcdc_attach_endpoint(dev, endpoint);
  68. /* At least one device was successfully attached.*/
  69. if (ret == -ENODEV && endpoint)
  70. return 0;
  71. return ret;
  72. }