display.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (C) 2009 Nokia Corporation
  3. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  4. *
  5. * Some code and ideas taken from drivers/video/omap/ driver
  6. * by Imre Deak.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published by
  10. * the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #define DSS_SUBSYS_NAME "DISPLAY"
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/jiffies.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/of.h>
  26. #include "omapdss.h"
  27. static void omapdss_default_get_timings(struct omap_dss_device *dssdev,
  28. struct videomode *vm)
  29. {
  30. *vm = dssdev->panel.vm;
  31. }
  32. static LIST_HEAD(panel_list);
  33. static DEFINE_MUTEX(panel_list_mutex);
  34. static int disp_num_counter;
  35. int omapdss_register_display(struct omap_dss_device *dssdev)
  36. {
  37. struct omap_dss_driver *drv = dssdev->driver;
  38. struct list_head *cur;
  39. int id;
  40. /*
  41. * Note: this presumes that all displays either have an DT alias, or
  42. * none has.
  43. */
  44. id = of_alias_get_id(dssdev->dev->of_node, "display");
  45. if (id < 0)
  46. id = disp_num_counter++;
  47. snprintf(dssdev->alias, sizeof(dssdev->alias), "display%d", id);
  48. /* Use 'label' property for name, if it exists */
  49. of_property_read_string(dssdev->dev->of_node, "label", &dssdev->name);
  50. if (dssdev->name == NULL)
  51. dssdev->name = dssdev->alias;
  52. if (drv && drv->get_timings == NULL)
  53. drv->get_timings = omapdss_default_get_timings;
  54. mutex_lock(&panel_list_mutex);
  55. list_for_each(cur, &panel_list) {
  56. struct omap_dss_device *ldev = list_entry(cur,
  57. struct omap_dss_device,
  58. panel_list);
  59. if (strcmp(ldev->alias, dssdev->alias) > 0)
  60. break;
  61. }
  62. list_add_tail(&dssdev->panel_list, cur);
  63. mutex_unlock(&panel_list_mutex);
  64. return 0;
  65. }
  66. EXPORT_SYMBOL(omapdss_register_display);
  67. void omapdss_unregister_display(struct omap_dss_device *dssdev)
  68. {
  69. mutex_lock(&panel_list_mutex);
  70. list_del(&dssdev->panel_list);
  71. mutex_unlock(&panel_list_mutex);
  72. }
  73. EXPORT_SYMBOL(omapdss_unregister_display);
  74. bool omapdss_component_is_display(struct device_node *node)
  75. {
  76. struct omap_dss_device *dssdev;
  77. bool found = false;
  78. mutex_lock(&panel_list_mutex);
  79. list_for_each_entry(dssdev, &panel_list, panel_list) {
  80. if (dssdev->dev->of_node == node) {
  81. found = true;
  82. goto out;
  83. }
  84. }
  85. out:
  86. mutex_unlock(&panel_list_mutex);
  87. return found;
  88. }
  89. EXPORT_SYMBOL(omapdss_component_is_display);
  90. struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
  91. {
  92. if (!try_module_get(dssdev->owner))
  93. return NULL;
  94. if (get_device(dssdev->dev) == NULL) {
  95. module_put(dssdev->owner);
  96. return NULL;
  97. }
  98. return dssdev;
  99. }
  100. EXPORT_SYMBOL(omap_dss_get_device);
  101. void omap_dss_put_device(struct omap_dss_device *dssdev)
  102. {
  103. put_device(dssdev->dev);
  104. module_put(dssdev->owner);
  105. }
  106. EXPORT_SYMBOL(omap_dss_put_device);
  107. /*
  108. * ref count of the found device is incremented.
  109. * ref count of from-device is decremented.
  110. */
  111. struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
  112. {
  113. struct list_head *l;
  114. struct omap_dss_device *dssdev;
  115. mutex_lock(&panel_list_mutex);
  116. if (list_empty(&panel_list)) {
  117. dssdev = NULL;
  118. goto out;
  119. }
  120. if (from == NULL) {
  121. dssdev = list_first_entry(&panel_list, struct omap_dss_device,
  122. panel_list);
  123. omap_dss_get_device(dssdev);
  124. goto out;
  125. }
  126. omap_dss_put_device(from);
  127. list_for_each(l, &panel_list) {
  128. dssdev = list_entry(l, struct omap_dss_device, panel_list);
  129. if (dssdev == from) {
  130. if (list_is_last(l, &panel_list)) {
  131. dssdev = NULL;
  132. goto out;
  133. }
  134. dssdev = list_entry(l->next, struct omap_dss_device,
  135. panel_list);
  136. omap_dss_get_device(dssdev);
  137. goto out;
  138. }
  139. }
  140. WARN(1, "'from' dssdev not found\n");
  141. dssdev = NULL;
  142. out:
  143. mutex_unlock(&panel_list_mutex);
  144. return dssdev;
  145. }
  146. EXPORT_SYMBOL(omap_dss_get_next_device);