display.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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 <video/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. int dss_suspend_all_devices(void)
  74. {
  75. struct omap_dss_device *dssdev = NULL;
  76. for_each_dss_dev(dssdev) {
  77. if (!dssdev->driver)
  78. continue;
  79. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  80. dssdev->driver->disable(dssdev);
  81. dssdev->activate_after_resume = true;
  82. } else {
  83. dssdev->activate_after_resume = false;
  84. }
  85. }
  86. return 0;
  87. }
  88. int dss_resume_all_devices(void)
  89. {
  90. struct omap_dss_device *dssdev = NULL;
  91. for_each_dss_dev(dssdev) {
  92. if (!dssdev->driver)
  93. continue;
  94. if (dssdev->activate_after_resume) {
  95. dssdev->driver->enable(dssdev);
  96. dssdev->activate_after_resume = false;
  97. }
  98. }
  99. return 0;
  100. }
  101. void dss_disable_all_devices(void)
  102. {
  103. struct omap_dss_device *dssdev = NULL;
  104. for_each_dss_dev(dssdev) {
  105. if (!dssdev->driver)
  106. continue;
  107. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  108. dssdev->driver->disable(dssdev);
  109. }
  110. }
  111. static LIST_HEAD(panel_list);
  112. static DEFINE_MUTEX(panel_list_mutex);
  113. static int disp_num_counter;
  114. int omapdss_register_display(struct omap_dss_device *dssdev)
  115. {
  116. struct omap_dss_driver *drv = dssdev->driver;
  117. int id;
  118. /*
  119. * Note: this presumes all the displays are either using DT or non-DT,
  120. * which normally should be the case. This also presumes that all
  121. * displays either have an DT alias, or none has.
  122. */
  123. if (dssdev->dev->of_node) {
  124. id = of_alias_get_id(dssdev->dev->of_node, "display");
  125. if (id < 0)
  126. id = disp_num_counter++;
  127. } else {
  128. id = disp_num_counter++;
  129. }
  130. snprintf(dssdev->alias, sizeof(dssdev->alias), "display%d", id);
  131. /* Use 'label' property for name, if it exists */
  132. if (dssdev->dev->of_node)
  133. of_property_read_string(dssdev->dev->of_node, "label",
  134. &dssdev->name);
  135. if (dssdev->name == NULL)
  136. dssdev->name = dssdev->alias;
  137. if (drv && drv->get_resolution == NULL)
  138. drv->get_resolution = omapdss_default_get_resolution;
  139. if (drv && drv->get_recommended_bpp == NULL)
  140. drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
  141. if (drv && drv->get_timings == NULL)
  142. drv->get_timings = omapdss_default_get_timings;
  143. mutex_lock(&panel_list_mutex);
  144. list_add_tail(&dssdev->panel_list, &panel_list);
  145. mutex_unlock(&panel_list_mutex);
  146. return 0;
  147. }
  148. EXPORT_SYMBOL(omapdss_register_display);
  149. void omapdss_unregister_display(struct omap_dss_device *dssdev)
  150. {
  151. mutex_lock(&panel_list_mutex);
  152. list_del(&dssdev->panel_list);
  153. mutex_unlock(&panel_list_mutex);
  154. }
  155. EXPORT_SYMBOL(omapdss_unregister_display);
  156. struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
  157. {
  158. if (!try_module_get(dssdev->owner))
  159. return NULL;
  160. if (get_device(dssdev->dev) == NULL) {
  161. module_put(dssdev->owner);
  162. return NULL;
  163. }
  164. return dssdev;
  165. }
  166. EXPORT_SYMBOL(omap_dss_get_device);
  167. void omap_dss_put_device(struct omap_dss_device *dssdev)
  168. {
  169. put_device(dssdev->dev);
  170. module_put(dssdev->owner);
  171. }
  172. EXPORT_SYMBOL(omap_dss_put_device);
  173. /*
  174. * ref count of the found device is incremented.
  175. * ref count of from-device is decremented.
  176. */
  177. struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
  178. {
  179. struct list_head *l;
  180. struct omap_dss_device *dssdev;
  181. mutex_lock(&panel_list_mutex);
  182. if (list_empty(&panel_list)) {
  183. dssdev = NULL;
  184. goto out;
  185. }
  186. if (from == NULL) {
  187. dssdev = list_first_entry(&panel_list, struct omap_dss_device,
  188. panel_list);
  189. omap_dss_get_device(dssdev);
  190. goto out;
  191. }
  192. omap_dss_put_device(from);
  193. list_for_each(l, &panel_list) {
  194. dssdev = list_entry(l, struct omap_dss_device, panel_list);
  195. if (dssdev == from) {
  196. if (list_is_last(l, &panel_list)) {
  197. dssdev = NULL;
  198. goto out;
  199. }
  200. dssdev = list_entry(l->next, struct omap_dss_device,
  201. panel_list);
  202. omap_dss_get_device(dssdev);
  203. goto out;
  204. }
  205. }
  206. WARN(1, "'from' dssdev not found\n");
  207. dssdev = NULL;
  208. out:
  209. mutex_unlock(&panel_list_mutex);
  210. return dssdev;
  211. }
  212. EXPORT_SYMBOL(omap_dss_get_next_device);
  213. struct omap_dss_device *omap_dss_find_device(void *data,
  214. int (*match)(struct omap_dss_device *dssdev, void *data))
  215. {
  216. struct omap_dss_device *dssdev = NULL;
  217. while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
  218. if (match(dssdev, data))
  219. return dssdev;
  220. }
  221. return NULL;
  222. }
  223. EXPORT_SYMBOL(omap_dss_find_device);
  224. void videomode_to_omap_video_timings(const struct videomode *vm,
  225. struct omap_video_timings *ovt)
  226. {
  227. memset(ovt, 0, sizeof(*ovt));
  228. ovt->pixelclock = vm->pixelclock;
  229. ovt->x_res = vm->hactive;
  230. ovt->hbp = vm->hback_porch;
  231. ovt->hfp = vm->hfront_porch;
  232. ovt->hsw = vm->hsync_len;
  233. ovt->y_res = vm->vactive;
  234. ovt->vbp = vm->vback_porch;
  235. ovt->vfp = vm->vfront_porch;
  236. ovt->vsw = vm->vsync_len;
  237. ovt->vsync_level = vm->flags & DISPLAY_FLAGS_VSYNC_HIGH ?
  238. OMAPDSS_SIG_ACTIVE_HIGH :
  239. OMAPDSS_SIG_ACTIVE_LOW;
  240. ovt->hsync_level = vm->flags & DISPLAY_FLAGS_HSYNC_HIGH ?
  241. OMAPDSS_SIG_ACTIVE_HIGH :
  242. OMAPDSS_SIG_ACTIVE_LOW;
  243. ovt->de_level = vm->flags & DISPLAY_FLAGS_DE_HIGH ?
  244. OMAPDSS_SIG_ACTIVE_HIGH :
  245. OMAPDSS_SIG_ACTIVE_LOW;
  246. ovt->data_pclk_edge = vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE ?
  247. OMAPDSS_DRIVE_SIG_RISING_EDGE :
  248. OMAPDSS_DRIVE_SIG_FALLING_EDGE;
  249. ovt->sync_pclk_edge = ovt->data_pclk_edge;
  250. }
  251. EXPORT_SYMBOL(videomode_to_omap_video_timings);
  252. void omap_video_timings_to_videomode(const struct omap_video_timings *ovt,
  253. struct videomode *vm)
  254. {
  255. memset(vm, 0, sizeof(*vm));
  256. vm->pixelclock = ovt->pixelclock;
  257. vm->hactive = ovt->x_res;
  258. vm->hback_porch = ovt->hbp;
  259. vm->hfront_porch = ovt->hfp;
  260. vm->hsync_len = ovt->hsw;
  261. vm->vactive = ovt->y_res;
  262. vm->vback_porch = ovt->vbp;
  263. vm->vfront_porch = ovt->vfp;
  264. vm->vsync_len = ovt->vsw;
  265. if (ovt->hsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
  266. vm->flags |= DISPLAY_FLAGS_HSYNC_HIGH;
  267. else
  268. vm->flags |= DISPLAY_FLAGS_HSYNC_LOW;
  269. if (ovt->vsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
  270. vm->flags |= DISPLAY_FLAGS_VSYNC_HIGH;
  271. else
  272. vm->flags |= DISPLAY_FLAGS_VSYNC_LOW;
  273. if (ovt->de_level == OMAPDSS_SIG_ACTIVE_HIGH)
  274. vm->flags |= DISPLAY_FLAGS_DE_HIGH;
  275. else
  276. vm->flags |= DISPLAY_FLAGS_DE_LOW;
  277. if (ovt->data_pclk_edge == OMAPDSS_DRIVE_SIG_RISING_EDGE)
  278. vm->flags |= DISPLAY_FLAGS_PIXDATA_POSEDGE;
  279. else
  280. vm->flags |= DISPLAY_FLAGS_PIXDATA_NEGEDGE;
  281. }
  282. EXPORT_SYMBOL(omap_video_timings_to_videomode);