display.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. void omap_dss_get_device(struct omap_dss_device *dssdev)
  124. {
  125. get_device(&dssdev->dev);
  126. }
  127. EXPORT_SYMBOL(omap_dss_get_device);
  128. void omap_dss_put_device(struct omap_dss_device *dssdev)
  129. {
  130. put_device(&dssdev->dev);
  131. }
  132. EXPORT_SYMBOL(omap_dss_put_device);
  133. /* ref count of the found device is incremented. ref count
  134. * of from-device is decremented. */
  135. struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
  136. {
  137. struct device *dev;
  138. struct device *dev_start = NULL;
  139. struct omap_dss_device *dssdev = NULL;
  140. int match(struct device *dev, void *data)
  141. {
  142. return 1;
  143. }
  144. if (from)
  145. dev_start = &from->dev;
  146. dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
  147. if (dev)
  148. dssdev = to_dss_device(dev);
  149. if (from)
  150. put_device(&from->dev);
  151. return dssdev;
  152. }
  153. EXPORT_SYMBOL(omap_dss_get_next_device);
  154. struct omap_dss_device *omap_dss_find_device(void *data,
  155. int (*match)(struct omap_dss_device *dssdev, void *data))
  156. {
  157. struct omap_dss_device *dssdev = NULL;
  158. while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
  159. if (match(dssdev, data))
  160. return dssdev;
  161. }
  162. return NULL;
  163. }
  164. EXPORT_SYMBOL(omap_dss_find_device);
  165. int omap_dss_start_device(struct omap_dss_device *dssdev)
  166. {
  167. if (!dssdev->driver) {
  168. DSSDBG("no driver\n");
  169. return -ENODEV;
  170. }
  171. if (!try_module_get(dssdev->dev.driver->owner)) {
  172. return -ENODEV;
  173. }
  174. return 0;
  175. }
  176. EXPORT_SYMBOL(omap_dss_start_device);
  177. void omap_dss_stop_device(struct omap_dss_device *dssdev)
  178. {
  179. module_put(dssdev->dev.driver->owner);
  180. }
  181. EXPORT_SYMBOL(omap_dss_stop_device);