display.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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_resolution(struct omap_dss_device *dssdev,
  30. u16 *xres, u16 *yres)
  31. {
  32. *xres = dssdev->panel.vm.hactive;
  33. *yres = dssdev->panel.vm.vactive;
  34. }
  35. EXPORT_SYMBOL(omapdss_default_get_resolution);
  36. int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
  37. {
  38. switch (dssdev->type) {
  39. case OMAP_DISPLAY_TYPE_DPI:
  40. if (dssdev->phy.dpi.data_lines == 24)
  41. return 24;
  42. else
  43. return 16;
  44. case OMAP_DISPLAY_TYPE_DBI:
  45. if (dssdev->ctrl.pixel_size == 24)
  46. return 24;
  47. else
  48. return 16;
  49. case OMAP_DISPLAY_TYPE_DSI:
  50. if (dssdev->panel.dsi_pix_fmt == OMAP_DSS_DSI_FMT_RGB565)
  51. return 16;
  52. else
  53. return 24;
  54. case OMAP_DISPLAY_TYPE_VENC:
  55. case OMAP_DISPLAY_TYPE_SDI:
  56. case OMAP_DISPLAY_TYPE_HDMI:
  57. case OMAP_DISPLAY_TYPE_DVI:
  58. return 24;
  59. default:
  60. BUG();
  61. return 0;
  62. }
  63. }
  64. EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
  65. void omapdss_default_get_timings(struct omap_dss_device *dssdev,
  66. struct videomode *vm)
  67. {
  68. *vm = dssdev->panel.vm;
  69. }
  70. EXPORT_SYMBOL(omapdss_default_get_timings);
  71. static LIST_HEAD(panel_list);
  72. static DEFINE_MUTEX(panel_list_mutex);
  73. static int disp_num_counter;
  74. int omapdss_register_display(struct omap_dss_device *dssdev)
  75. {
  76. struct omap_dss_driver *drv = dssdev->driver;
  77. struct list_head *cur;
  78. int id;
  79. /*
  80. * Note: this presumes that all displays either have an DT alias, or
  81. * none has.
  82. */
  83. id = of_alias_get_id(dssdev->dev->of_node, "display");
  84. if (id < 0)
  85. id = disp_num_counter++;
  86. snprintf(dssdev->alias, sizeof(dssdev->alias), "display%d", id);
  87. /* Use 'label' property for name, if it exists */
  88. of_property_read_string(dssdev->dev->of_node, "label", &dssdev->name);
  89. if (dssdev->name == NULL)
  90. dssdev->name = dssdev->alias;
  91. if (drv && drv->get_resolution == NULL)
  92. drv->get_resolution = omapdss_default_get_resolution;
  93. if (drv && drv->get_recommended_bpp == NULL)
  94. drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
  95. if (drv && drv->get_timings == NULL)
  96. drv->get_timings = omapdss_default_get_timings;
  97. mutex_lock(&panel_list_mutex);
  98. list_for_each(cur, &panel_list) {
  99. struct omap_dss_device *ldev = list_entry(cur,
  100. struct omap_dss_device,
  101. panel_list);
  102. if (strcmp(ldev->alias, dssdev->alias) > 0)
  103. break;
  104. }
  105. list_add_tail(&dssdev->panel_list, cur);
  106. mutex_unlock(&panel_list_mutex);
  107. return 0;
  108. }
  109. EXPORT_SYMBOL(omapdss_register_display);
  110. void omapdss_unregister_display(struct omap_dss_device *dssdev)
  111. {
  112. mutex_lock(&panel_list_mutex);
  113. list_del(&dssdev->panel_list);
  114. mutex_unlock(&panel_list_mutex);
  115. }
  116. EXPORT_SYMBOL(omapdss_unregister_display);
  117. bool omapdss_component_is_display(struct device_node *node)
  118. {
  119. struct omap_dss_device *dssdev;
  120. bool found = false;
  121. mutex_lock(&panel_list_mutex);
  122. list_for_each_entry(dssdev, &panel_list, panel_list) {
  123. if (dssdev->dev->of_node == node) {
  124. found = true;
  125. goto out;
  126. }
  127. }
  128. out:
  129. mutex_unlock(&panel_list_mutex);
  130. return found;
  131. }
  132. EXPORT_SYMBOL(omapdss_component_is_display);
  133. struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
  134. {
  135. if (!try_module_get(dssdev->owner))
  136. return NULL;
  137. if (get_device(dssdev->dev) == NULL) {
  138. module_put(dssdev->owner);
  139. return NULL;
  140. }
  141. return dssdev;
  142. }
  143. EXPORT_SYMBOL(omap_dss_get_device);
  144. void omap_dss_put_device(struct omap_dss_device *dssdev)
  145. {
  146. put_device(dssdev->dev);
  147. module_put(dssdev->owner);
  148. }
  149. EXPORT_SYMBOL(omap_dss_put_device);
  150. /*
  151. * ref count of the found device is incremented.
  152. * ref count of from-device is decremented.
  153. */
  154. struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
  155. {
  156. struct list_head *l;
  157. struct omap_dss_device *dssdev;
  158. mutex_lock(&panel_list_mutex);
  159. if (list_empty(&panel_list)) {
  160. dssdev = NULL;
  161. goto out;
  162. }
  163. if (from == NULL) {
  164. dssdev = list_first_entry(&panel_list, struct omap_dss_device,
  165. panel_list);
  166. omap_dss_get_device(dssdev);
  167. goto out;
  168. }
  169. omap_dss_put_device(from);
  170. list_for_each(l, &panel_list) {
  171. dssdev = list_entry(l, struct omap_dss_device, panel_list);
  172. if (dssdev == from) {
  173. if (list_is_last(l, &panel_list)) {
  174. dssdev = NULL;
  175. goto out;
  176. }
  177. dssdev = list_entry(l->next, struct omap_dss_device,
  178. panel_list);
  179. omap_dss_get_device(dssdev);
  180. goto out;
  181. }
  182. }
  183. WARN(1, "'from' dssdev not found\n");
  184. dssdev = NULL;
  185. out:
  186. mutex_unlock(&panel_list_mutex);
  187. return dssdev;
  188. }
  189. EXPORT_SYMBOL(omap_dss_get_next_device);
  190. struct omap_dss_device *omap_dss_find_device(void *data,
  191. int (*match)(struct omap_dss_device *dssdev, void *data))
  192. {
  193. struct omap_dss_device *dssdev = NULL;
  194. while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
  195. if (match(dssdev, data))
  196. return dssdev;
  197. }
  198. return NULL;
  199. }
  200. EXPORT_SYMBOL(omap_dss_find_device);