display.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. #include "dss.h"
  30. #include "dss_features.h"
  31. void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
  32. u16 *xres, u16 *yres)
  33. {
  34. *xres = dssdev->panel.timings.x_res;
  35. *yres = dssdev->panel.timings.y_res;
  36. }
  37. EXPORT_SYMBOL(omapdss_default_get_resolution);
  38. int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
  39. {
  40. switch (dssdev->type) {
  41. case OMAP_DISPLAY_TYPE_DPI:
  42. if (dssdev->phy.dpi.data_lines == 24)
  43. return 24;
  44. else
  45. return 16;
  46. case OMAP_DISPLAY_TYPE_DBI:
  47. if (dssdev->ctrl.pixel_size == 24)
  48. return 24;
  49. else
  50. return 16;
  51. case OMAP_DISPLAY_TYPE_DSI:
  52. if (dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) > 16)
  53. return 24;
  54. else
  55. return 16;
  56. case OMAP_DISPLAY_TYPE_VENC:
  57. case OMAP_DISPLAY_TYPE_SDI:
  58. case OMAP_DISPLAY_TYPE_HDMI:
  59. case OMAP_DISPLAY_TYPE_DVI:
  60. return 24;
  61. default:
  62. BUG();
  63. return 0;
  64. }
  65. }
  66. EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
  67. void omapdss_default_get_timings(struct omap_dss_device *dssdev,
  68. struct omap_video_timings *timings)
  69. {
  70. *timings = dssdev->panel.timings;
  71. }
  72. EXPORT_SYMBOL(omapdss_default_get_timings);
  73. static LIST_HEAD(panel_list);
  74. static DEFINE_MUTEX(panel_list_mutex);
  75. static int disp_num_counter;
  76. int omapdss_register_display(struct omap_dss_device *dssdev)
  77. {
  78. struct omap_dss_driver *drv = dssdev->driver;
  79. int id;
  80. /*
  81. * Note: this presumes all the displays are either using DT or non-DT,
  82. * which normally should be the case. This also presumes that all
  83. * displays either have an DT alias, or none has.
  84. */
  85. if (dssdev->dev->of_node) {
  86. id = of_alias_get_id(dssdev->dev->of_node, "display");
  87. if (id < 0)
  88. id = disp_num_counter++;
  89. } else {
  90. id = disp_num_counter++;
  91. }
  92. snprintf(dssdev->alias, sizeof(dssdev->alias), "display%d", id);
  93. /* Use 'label' property for name, if it exists */
  94. if (dssdev->dev->of_node)
  95. of_property_read_string(dssdev->dev->of_node, "label",
  96. &dssdev->name);
  97. if (dssdev->name == NULL)
  98. dssdev->name = dssdev->alias;
  99. if (drv && drv->get_resolution == NULL)
  100. drv->get_resolution = omapdss_default_get_resolution;
  101. if (drv && drv->get_recommended_bpp == NULL)
  102. drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
  103. if (drv && drv->get_timings == NULL)
  104. drv->get_timings = omapdss_default_get_timings;
  105. mutex_lock(&panel_list_mutex);
  106. list_add_tail(&dssdev->panel_list, &panel_list);
  107. mutex_unlock(&panel_list_mutex);
  108. return 0;
  109. }
  110. EXPORT_SYMBOL(omapdss_register_display);
  111. void omapdss_unregister_display(struct omap_dss_device *dssdev)
  112. {
  113. mutex_lock(&panel_list_mutex);
  114. list_del(&dssdev->panel_list);
  115. mutex_unlock(&panel_list_mutex);
  116. }
  117. EXPORT_SYMBOL(omapdss_unregister_display);
  118. struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
  119. {
  120. if (!try_module_get(dssdev->owner))
  121. return NULL;
  122. if (get_device(dssdev->dev) == NULL) {
  123. module_put(dssdev->owner);
  124. return NULL;
  125. }
  126. return dssdev;
  127. }
  128. EXPORT_SYMBOL(omap_dss_get_device);
  129. void omap_dss_put_device(struct omap_dss_device *dssdev)
  130. {
  131. put_device(dssdev->dev);
  132. module_put(dssdev->owner);
  133. }
  134. EXPORT_SYMBOL(omap_dss_put_device);
  135. /*
  136. * ref count of the found device is incremented.
  137. * ref count of from-device is decremented.
  138. */
  139. struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
  140. {
  141. struct list_head *l;
  142. struct omap_dss_device *dssdev;
  143. mutex_lock(&panel_list_mutex);
  144. if (list_empty(&panel_list)) {
  145. dssdev = NULL;
  146. goto out;
  147. }
  148. if (from == NULL) {
  149. dssdev = list_first_entry(&panel_list, struct omap_dss_device,
  150. panel_list);
  151. omap_dss_get_device(dssdev);
  152. goto out;
  153. }
  154. omap_dss_put_device(from);
  155. list_for_each(l, &panel_list) {
  156. dssdev = list_entry(l, struct omap_dss_device, panel_list);
  157. if (dssdev == from) {
  158. if (list_is_last(l, &panel_list)) {
  159. dssdev = NULL;
  160. goto out;
  161. }
  162. dssdev = list_entry(l->next, struct omap_dss_device,
  163. panel_list);
  164. omap_dss_get_device(dssdev);
  165. goto out;
  166. }
  167. }
  168. WARN(1, "'from' dssdev not found\n");
  169. dssdev = NULL;
  170. out:
  171. mutex_unlock(&panel_list_mutex);
  172. return dssdev;
  173. }
  174. EXPORT_SYMBOL(omap_dss_get_next_device);
  175. struct omap_dss_device *omap_dss_find_device(void *data,
  176. int (*match)(struct omap_dss_device *dssdev, void *data))
  177. {
  178. struct omap_dss_device *dssdev = NULL;
  179. while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
  180. if (match(dssdev, data))
  181. return dssdev;
  182. }
  183. return NULL;
  184. }
  185. EXPORT_SYMBOL(omap_dss_find_device);
  186. void videomode_to_omap_video_timings(const struct videomode *vm,
  187. struct omap_video_timings *ovt)
  188. {
  189. memset(ovt, 0, sizeof(*ovt));
  190. ovt->pixelclock = vm->pixelclock;
  191. ovt->x_res = vm->hactive;
  192. ovt->hbp = vm->hback_porch;
  193. ovt->hfp = vm->hfront_porch;
  194. ovt->hsw = vm->hsync_len;
  195. ovt->y_res = vm->vactive;
  196. ovt->vbp = vm->vback_porch;
  197. ovt->vfp = vm->vfront_porch;
  198. ovt->vsw = vm->vsync_len;
  199. ovt->vsync_level = vm->flags & DISPLAY_FLAGS_VSYNC_HIGH ?
  200. OMAPDSS_SIG_ACTIVE_HIGH :
  201. OMAPDSS_SIG_ACTIVE_LOW;
  202. ovt->hsync_level = vm->flags & DISPLAY_FLAGS_HSYNC_HIGH ?
  203. OMAPDSS_SIG_ACTIVE_HIGH :
  204. OMAPDSS_SIG_ACTIVE_LOW;
  205. ovt->de_level = vm->flags & DISPLAY_FLAGS_DE_HIGH ?
  206. OMAPDSS_SIG_ACTIVE_HIGH :
  207. OMAPDSS_SIG_ACTIVE_LOW;
  208. ovt->data_pclk_edge = vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE ?
  209. OMAPDSS_DRIVE_SIG_RISING_EDGE :
  210. OMAPDSS_DRIVE_SIG_FALLING_EDGE;
  211. ovt->sync_pclk_edge = ovt->data_pclk_edge;
  212. }
  213. EXPORT_SYMBOL(videomode_to_omap_video_timings);
  214. void omap_video_timings_to_videomode(const struct omap_video_timings *ovt,
  215. struct videomode *vm)
  216. {
  217. memset(vm, 0, sizeof(*vm));
  218. vm->pixelclock = ovt->pixelclock;
  219. vm->hactive = ovt->x_res;
  220. vm->hback_porch = ovt->hbp;
  221. vm->hfront_porch = ovt->hfp;
  222. vm->hsync_len = ovt->hsw;
  223. vm->vactive = ovt->y_res;
  224. vm->vback_porch = ovt->vbp;
  225. vm->vfront_porch = ovt->vfp;
  226. vm->vsync_len = ovt->vsw;
  227. if (ovt->hsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
  228. vm->flags |= DISPLAY_FLAGS_HSYNC_HIGH;
  229. else
  230. vm->flags |= DISPLAY_FLAGS_HSYNC_LOW;
  231. if (ovt->vsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
  232. vm->flags |= DISPLAY_FLAGS_VSYNC_HIGH;
  233. else
  234. vm->flags |= DISPLAY_FLAGS_VSYNC_LOW;
  235. if (ovt->de_level == OMAPDSS_SIG_ACTIVE_HIGH)
  236. vm->flags |= DISPLAY_FLAGS_DE_HIGH;
  237. else
  238. vm->flags |= DISPLAY_FLAGS_DE_LOW;
  239. if (ovt->data_pclk_edge == OMAPDSS_DRIVE_SIG_RISING_EDGE)
  240. vm->flags |= DISPLAY_FLAGS_PIXDATA_POSEDGE;
  241. else
  242. vm->flags |= DISPLAY_FLAGS_PIXDATA_NEGEDGE;
  243. }
  244. EXPORT_SYMBOL(omap_video_timings_to_videomode);