display.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. int dss_init_device(struct platform_device *pdev,
  72. struct omap_dss_device *dssdev)
  73. {
  74. int r;
  75. r = display_init_sysfs(pdev, dssdev);
  76. if (r) {
  77. omapdss_output_unset_device(dssdev->output);
  78. return r;
  79. }
  80. return 0;
  81. }
  82. void dss_uninit_device(struct platform_device *pdev,
  83. struct omap_dss_device *dssdev)
  84. {
  85. display_uninit_sysfs(pdev, dssdev);
  86. }
  87. static int dss_suspend_device(struct device *dev, void *data)
  88. {
  89. struct omap_dss_device *dssdev = to_dss_device(dev);
  90. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  91. dssdev->activate_after_resume = false;
  92. return 0;
  93. }
  94. dssdev->driver->disable(dssdev);
  95. dssdev->activate_after_resume = true;
  96. return 0;
  97. }
  98. int dss_suspend_all_devices(void)
  99. {
  100. int r;
  101. struct bus_type *bus = dss_get_bus();
  102. r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
  103. if (r) {
  104. /* resume all displays that were suspended */
  105. dss_resume_all_devices();
  106. return r;
  107. }
  108. return 0;
  109. }
  110. static int dss_resume_device(struct device *dev, void *data)
  111. {
  112. int r;
  113. struct omap_dss_device *dssdev = to_dss_device(dev);
  114. if (dssdev->activate_after_resume) {
  115. r = dssdev->driver->enable(dssdev);
  116. if (r)
  117. return r;
  118. }
  119. dssdev->activate_after_resume = false;
  120. return 0;
  121. }
  122. int dss_resume_all_devices(void)
  123. {
  124. struct bus_type *bus = dss_get_bus();
  125. return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
  126. }
  127. static int dss_disable_device(struct device *dev, void *data)
  128. {
  129. struct omap_dss_device *dssdev = to_dss_device(dev);
  130. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
  131. dssdev->driver->disable(dssdev);
  132. return 0;
  133. }
  134. void dss_disable_all_devices(void)
  135. {
  136. struct bus_type *bus = dss_get_bus();
  137. bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
  138. }
  139. void omap_dss_get_device(struct omap_dss_device *dssdev)
  140. {
  141. get_device(&dssdev->dev);
  142. }
  143. EXPORT_SYMBOL(omap_dss_get_device);
  144. void omap_dss_put_device(struct omap_dss_device *dssdev)
  145. {
  146. put_device(&dssdev->dev);
  147. }
  148. EXPORT_SYMBOL(omap_dss_put_device);
  149. /* ref count of the found device is incremented. ref count
  150. * of from-device is decremented. */
  151. struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
  152. {
  153. struct device *dev;
  154. struct device *dev_start = NULL;
  155. struct omap_dss_device *dssdev = NULL;
  156. int match(struct device *dev, void *data)
  157. {
  158. return 1;
  159. }
  160. if (from)
  161. dev_start = &from->dev;
  162. dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
  163. if (dev)
  164. dssdev = to_dss_device(dev);
  165. if (from)
  166. put_device(&from->dev);
  167. return dssdev;
  168. }
  169. EXPORT_SYMBOL(omap_dss_get_next_device);
  170. struct omap_dss_device *omap_dss_find_device(void *data,
  171. int (*match)(struct omap_dss_device *dssdev, void *data))
  172. {
  173. struct omap_dss_device *dssdev = NULL;
  174. while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
  175. if (match(dssdev, data))
  176. return dssdev;
  177. }
  178. return NULL;
  179. }
  180. EXPORT_SYMBOL(omap_dss_find_device);
  181. int omap_dss_start_device(struct omap_dss_device *dssdev)
  182. {
  183. if (!dssdev->driver) {
  184. DSSDBG("no driver\n");
  185. return -ENODEV;
  186. }
  187. if (!try_module_get(dssdev->dev.driver->owner)) {
  188. return -ENODEV;
  189. }
  190. return 0;
  191. }
  192. EXPORT_SYMBOL(omap_dss_start_device);
  193. void omap_dss_stop_device(struct omap_dss_device *dssdev)
  194. {
  195. module_put(dssdev->dev.driver->owner);
  196. }
  197. EXPORT_SYMBOL(omap_dss_stop_device);