drm_panel.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C) 2013, NVIDIA Corporation. All rights reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sub license,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the
  12. * next paragraph) shall be included in all copies or substantial portions
  13. * of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <linux/err.h>
  24. #include <linux/module.h>
  25. #include <drm/drm_crtc.h>
  26. #include <drm/drm_panel.h>
  27. static DEFINE_MUTEX(panel_lock);
  28. static LIST_HEAD(panel_list);
  29. void drm_panel_init(struct drm_panel *panel)
  30. {
  31. INIT_LIST_HEAD(&panel->list);
  32. }
  33. EXPORT_SYMBOL(drm_panel_init);
  34. int drm_panel_add(struct drm_panel *panel)
  35. {
  36. mutex_lock(&panel_lock);
  37. list_add_tail(&panel->list, &panel_list);
  38. mutex_unlock(&panel_lock);
  39. return 0;
  40. }
  41. EXPORT_SYMBOL(drm_panel_add);
  42. void drm_panel_remove(struct drm_panel *panel)
  43. {
  44. mutex_lock(&panel_lock);
  45. list_del_init(&panel->list);
  46. mutex_unlock(&panel_lock);
  47. }
  48. EXPORT_SYMBOL(drm_panel_remove);
  49. int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector)
  50. {
  51. if (panel->connector)
  52. return -EBUSY;
  53. panel->connector = connector;
  54. panel->drm = connector->dev;
  55. return 0;
  56. }
  57. EXPORT_SYMBOL(drm_panel_attach);
  58. int drm_panel_detach(struct drm_panel *panel)
  59. {
  60. panel->connector = NULL;
  61. panel->drm = NULL;
  62. return 0;
  63. }
  64. EXPORT_SYMBOL(drm_panel_detach);
  65. #ifdef CONFIG_OF
  66. struct drm_panel *of_drm_find_panel(struct device_node *np)
  67. {
  68. struct drm_panel *panel;
  69. mutex_lock(&panel_lock);
  70. list_for_each_entry(panel, &panel_list, list) {
  71. if (panel->dev->of_node == np) {
  72. mutex_unlock(&panel_lock);
  73. return panel;
  74. }
  75. }
  76. mutex_unlock(&panel_lock);
  77. return NULL;
  78. }
  79. EXPORT_SYMBOL(of_drm_find_panel);
  80. #endif
  81. MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
  82. MODULE_DESCRIPTION("DRM panel infrastructure");
  83. MODULE_LICENSE("GPL and additional rights");