drm_bridge.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2014 Samsung Electronics Co., Ltd
  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/drmP.h"
  27. static DEFINE_MUTEX(bridge_lock);
  28. static LIST_HEAD(bridge_list);
  29. int drm_bridge_add(struct drm_bridge *bridge)
  30. {
  31. mutex_lock(&bridge_lock);
  32. list_add_tail(&bridge->list, &bridge_list);
  33. mutex_unlock(&bridge_lock);
  34. return 0;
  35. }
  36. EXPORT_SYMBOL(drm_bridge_add);
  37. void drm_bridge_remove(struct drm_bridge *bridge)
  38. {
  39. mutex_lock(&bridge_lock);
  40. list_del_init(&bridge->list);
  41. mutex_unlock(&bridge_lock);
  42. }
  43. EXPORT_SYMBOL(drm_bridge_remove);
  44. int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge)
  45. {
  46. if (!dev || !bridge)
  47. return -EINVAL;
  48. if (bridge->dev)
  49. return -EBUSY;
  50. bridge->dev = dev;
  51. if (bridge->funcs->attach)
  52. return bridge->funcs->attach(bridge);
  53. return 0;
  54. }
  55. EXPORT_SYMBOL(drm_bridge_attach);
  56. #ifdef CONFIG_OF
  57. struct drm_bridge *of_drm_find_bridge(struct device_node *np)
  58. {
  59. struct drm_bridge *bridge;
  60. mutex_lock(&bridge_lock);
  61. list_for_each_entry(bridge, &bridge_list, list) {
  62. if (bridge->of_node == np) {
  63. mutex_unlock(&bridge_lock);
  64. return bridge;
  65. }
  66. }
  67. mutex_unlock(&bridge_lock);
  68. return NULL;
  69. }
  70. EXPORT_SYMBOL(of_drm_find_bridge);
  71. #endif
  72. MODULE_AUTHOR("Ajay Kumar <ajaykumar.rs@samsung.com>");
  73. MODULE_DESCRIPTION("DRM bridge infrastructure");
  74. MODULE_LICENSE("GPL and additional rights");