display.c 7.5 KB

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