display.c 4.5 KB

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