display.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 all the displays are either using DT or non-DT,
  81. * which normally should be the case. This also presumes that all
  82. * displays either have an DT alias, or none has.
  83. */
  84. if (dssdev->dev->of_node) {
  85. id = of_alias_get_id(dssdev->dev->of_node, "display");
  86. if (id < 0)
  87. id = disp_num_counter++;
  88. } else {
  89. id = disp_num_counter++;
  90. }
  91. snprintf(dssdev->alias, sizeof(dssdev->alias), "display%d", id);
  92. /* Use 'label' property for name, if it exists */
  93. if (dssdev->dev->of_node)
  94. of_property_read_string(dssdev->dev->of_node, "label",
  95. &dssdev->name);
  96. if (dssdev->name == NULL)
  97. dssdev->name = dssdev->alias;
  98. if (drv && drv->get_resolution == NULL)
  99. drv->get_resolution = omapdss_default_get_resolution;
  100. if (drv && drv->get_recommended_bpp == NULL)
  101. drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
  102. if (drv && drv->get_timings == NULL)
  103. drv->get_timings = omapdss_default_get_timings;
  104. mutex_lock(&panel_list_mutex);
  105. list_for_each(cur, &panel_list) {
  106. struct omap_dss_device *ldev = list_entry(cur,
  107. struct omap_dss_device,
  108. panel_list);
  109. if (strcmp(ldev->alias, dssdev->alias) > 0)
  110. break;
  111. }
  112. list_add_tail(&dssdev->panel_list, cur);
  113. mutex_unlock(&panel_list_mutex);
  114. return 0;
  115. }
  116. EXPORT_SYMBOL(omapdss_register_display);
  117. void omapdss_unregister_display(struct omap_dss_device *dssdev)
  118. {
  119. mutex_lock(&panel_list_mutex);
  120. list_del(&dssdev->panel_list);
  121. mutex_unlock(&panel_list_mutex);
  122. }
  123. EXPORT_SYMBOL(omapdss_unregister_display);
  124. bool omapdss_component_is_display(struct device_node *node)
  125. {
  126. struct omap_dss_device *dssdev;
  127. bool found = false;
  128. mutex_lock(&panel_list_mutex);
  129. list_for_each_entry(dssdev, &panel_list, panel_list) {
  130. if (dssdev->dev->of_node == node) {
  131. found = true;
  132. goto out;
  133. }
  134. }
  135. out:
  136. mutex_unlock(&panel_list_mutex);
  137. return found;
  138. }
  139. EXPORT_SYMBOL(omapdss_component_is_display);
  140. struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
  141. {
  142. if (!try_module_get(dssdev->owner))
  143. return NULL;
  144. if (get_device(dssdev->dev) == NULL) {
  145. module_put(dssdev->owner);
  146. return NULL;
  147. }
  148. return dssdev;
  149. }
  150. EXPORT_SYMBOL(omap_dss_get_device);
  151. void omap_dss_put_device(struct omap_dss_device *dssdev)
  152. {
  153. put_device(dssdev->dev);
  154. module_put(dssdev->owner);
  155. }
  156. EXPORT_SYMBOL(omap_dss_put_device);
  157. /*
  158. * ref count of the found device is incremented.
  159. * ref count of from-device is decremented.
  160. */
  161. struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
  162. {
  163. struct list_head *l;
  164. struct omap_dss_device *dssdev;
  165. mutex_lock(&panel_list_mutex);
  166. if (list_empty(&panel_list)) {
  167. dssdev = NULL;
  168. goto out;
  169. }
  170. if (from == NULL) {
  171. dssdev = list_first_entry(&panel_list, struct omap_dss_device,
  172. panel_list);
  173. omap_dss_get_device(dssdev);
  174. goto out;
  175. }
  176. omap_dss_put_device(from);
  177. list_for_each(l, &panel_list) {
  178. dssdev = list_entry(l, struct omap_dss_device, panel_list);
  179. if (dssdev == from) {
  180. if (list_is_last(l, &panel_list)) {
  181. dssdev = NULL;
  182. goto out;
  183. }
  184. dssdev = list_entry(l->next, struct omap_dss_device,
  185. panel_list);
  186. omap_dss_get_device(dssdev);
  187. goto out;
  188. }
  189. }
  190. WARN(1, "'from' dssdev not found\n");
  191. dssdev = NULL;
  192. out:
  193. mutex_unlock(&panel_list_mutex);
  194. return dssdev;
  195. }
  196. EXPORT_SYMBOL(omap_dss_get_next_device);
  197. struct omap_dss_device *omap_dss_find_device(void *data,
  198. int (*match)(struct omap_dss_device *dssdev, void *data))
  199. {
  200. struct omap_dss_device *dssdev = NULL;
  201. while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
  202. if (match(dssdev, data))
  203. return dssdev;
  204. }
  205. return NULL;
  206. }
  207. EXPORT_SYMBOL(omap_dss_find_device);