display.c 5.4 KB

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