display.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. void omapdss_default_get_timings(struct omap_dss_device *dssdev,
  28. struct videomode *vm)
  29. {
  30. *vm = dssdev->panel.vm;
  31. }
  32. EXPORT_SYMBOL(omapdss_default_get_timings);
  33. static LIST_HEAD(panel_list);
  34. static DEFINE_MUTEX(panel_list_mutex);
  35. static int disp_num_counter;
  36. int omapdss_register_display(struct omap_dss_device *dssdev)
  37. {
  38. struct omap_dss_driver *drv = dssdev->driver;
  39. struct list_head *cur;
  40. int id;
  41. /*
  42. * Note: this presumes that all displays either have an DT alias, or
  43. * none has.
  44. */
  45. id = of_alias_get_id(dssdev->dev->of_node, "display");
  46. if (id < 0)
  47. id = disp_num_counter++;
  48. snprintf(dssdev->alias, sizeof(dssdev->alias), "display%d", id);
  49. /* Use 'label' property for name, if it exists */
  50. of_property_read_string(dssdev->dev->of_node, "label", &dssdev->name);
  51. if (dssdev->name == NULL)
  52. dssdev->name = dssdev->alias;
  53. if (drv && drv->get_timings == NULL)
  54. drv->get_timings = omapdss_default_get_timings;
  55. mutex_lock(&panel_list_mutex);
  56. list_for_each(cur, &panel_list) {
  57. struct omap_dss_device *ldev = list_entry(cur,
  58. struct omap_dss_device,
  59. panel_list);
  60. if (strcmp(ldev->alias, dssdev->alias) > 0)
  61. break;
  62. }
  63. list_add_tail(&dssdev->panel_list, cur);
  64. mutex_unlock(&panel_list_mutex);
  65. return 0;
  66. }
  67. EXPORT_SYMBOL(omapdss_register_display);
  68. void omapdss_unregister_display(struct omap_dss_device *dssdev)
  69. {
  70. mutex_lock(&panel_list_mutex);
  71. list_del(&dssdev->panel_list);
  72. mutex_unlock(&panel_list_mutex);
  73. }
  74. EXPORT_SYMBOL(omapdss_unregister_display);
  75. bool omapdss_component_is_display(struct device_node *node)
  76. {
  77. struct omap_dss_device *dssdev;
  78. bool found = false;
  79. mutex_lock(&panel_list_mutex);
  80. list_for_each_entry(dssdev, &panel_list, panel_list) {
  81. if (dssdev->dev->of_node == node) {
  82. found = true;
  83. goto out;
  84. }
  85. }
  86. out:
  87. mutex_unlock(&panel_list_mutex);
  88. return found;
  89. }
  90. EXPORT_SYMBOL(omapdss_component_is_display);
  91. struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
  92. {
  93. if (!try_module_get(dssdev->owner))
  94. return NULL;
  95. if (get_device(dssdev->dev) == NULL) {
  96. module_put(dssdev->owner);
  97. return NULL;
  98. }
  99. return dssdev;
  100. }
  101. EXPORT_SYMBOL(omap_dss_get_device);
  102. void omap_dss_put_device(struct omap_dss_device *dssdev)
  103. {
  104. put_device(dssdev->dev);
  105. module_put(dssdev->owner);
  106. }
  107. EXPORT_SYMBOL(omap_dss_put_device);
  108. /*
  109. * ref count of the found device is incremented.
  110. * ref count of from-device is decremented.
  111. */
  112. struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
  113. {
  114. struct list_head *l;
  115. struct omap_dss_device *dssdev;
  116. mutex_lock(&panel_list_mutex);
  117. if (list_empty(&panel_list)) {
  118. dssdev = NULL;
  119. goto out;
  120. }
  121. if (from == NULL) {
  122. dssdev = list_first_entry(&panel_list, struct omap_dss_device,
  123. panel_list);
  124. omap_dss_get_device(dssdev);
  125. goto out;
  126. }
  127. omap_dss_put_device(from);
  128. list_for_each(l, &panel_list) {
  129. dssdev = list_entry(l, struct omap_dss_device, panel_list);
  130. if (dssdev == from) {
  131. if (list_is_last(l, &panel_list)) {
  132. dssdev = NULL;
  133. goto out;
  134. }
  135. dssdev = list_entry(l->next, struct omap_dss_device,
  136. panel_list);
  137. omap_dss_get_device(dssdev);
  138. goto out;
  139. }
  140. }
  141. WARN(1, "'from' dssdev not found\n");
  142. dssdev = NULL;
  143. out:
  144. mutex_unlock(&panel_list_mutex);
  145. return dssdev;
  146. }
  147. EXPORT_SYMBOL(omap_dss_get_next_device);