display.c 8.1 KB

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