exynos_drm_core.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* exynos_drm_core.c
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4. * Author:
  5. * Inki Dae <inki.dae@samsung.com>
  6. * Joonyoung Shim <jy0922.shim@samsung.com>
  7. * Seung-Woo Kim <sw0312.kim@samsung.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 as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <drm/drmP.h>
  15. #include "exynos_drm_drv.h"
  16. #include "exynos_drm_crtc.h"
  17. #include "exynos_drm_fbdev.h"
  18. static LIST_HEAD(exynos_drm_subdrv_list);
  19. int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
  20. {
  21. if (!subdrv)
  22. return -EINVAL;
  23. list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
  24. return 0;
  25. }
  26. int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
  27. {
  28. if (!subdrv)
  29. return -EINVAL;
  30. list_del(&subdrv->list);
  31. return 0;
  32. }
  33. int exynos_drm_device_subdrv_probe(struct drm_device *dev)
  34. {
  35. struct exynos_drm_subdrv *subdrv, *n;
  36. int err;
  37. if (!dev)
  38. return -EINVAL;
  39. list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
  40. if (subdrv->probe) {
  41. subdrv->drm_dev = dev;
  42. /*
  43. * this probe callback would be called by sub driver
  44. * after setting of all resources to this sub driver,
  45. * such as clock, irq and register map are done.
  46. */
  47. err = subdrv->probe(dev, subdrv->dev);
  48. if (err) {
  49. DRM_DEBUG("exynos drm subdrv probe failed.\n");
  50. list_del(&subdrv->list);
  51. continue;
  52. }
  53. }
  54. }
  55. return 0;
  56. }
  57. int exynos_drm_device_subdrv_remove(struct drm_device *dev)
  58. {
  59. struct exynos_drm_subdrv *subdrv;
  60. if (!dev) {
  61. WARN(1, "Unexpected drm device unregister!\n");
  62. return -EINVAL;
  63. }
  64. list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
  65. if (subdrv->remove)
  66. subdrv->remove(dev, subdrv->dev);
  67. }
  68. return 0;
  69. }
  70. int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
  71. {
  72. struct exynos_drm_subdrv *subdrv;
  73. int ret;
  74. list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
  75. if (subdrv->open) {
  76. ret = subdrv->open(dev, subdrv->dev, file);
  77. if (ret)
  78. goto err;
  79. }
  80. }
  81. return 0;
  82. err:
  83. list_for_each_entry_continue_reverse(subdrv, &exynos_drm_subdrv_list, list) {
  84. if (subdrv->close)
  85. subdrv->close(dev, subdrv->dev, file);
  86. }
  87. return ret;
  88. }
  89. void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file)
  90. {
  91. struct exynos_drm_subdrv *subdrv;
  92. list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
  93. if (subdrv->close)
  94. subdrv->close(dev, subdrv->dev, file);
  95. }
  96. }