overlay.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * linux/drivers/video/omap2/dss/overlay.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 "OVERLAY"
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/err.h>
  26. #include <linux/sysfs.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/delay.h>
  29. #include <linux/slab.h>
  30. #include <video/omapdss.h>
  31. #include "dss.h"
  32. #include "dss_features.h"
  33. static int num_overlays;
  34. static struct omap_overlay *overlays;
  35. int omap_dss_get_num_overlays(void)
  36. {
  37. return num_overlays;
  38. }
  39. EXPORT_SYMBOL(omap_dss_get_num_overlays);
  40. struct omap_overlay *omap_dss_get_overlay(int num)
  41. {
  42. if (num >= num_overlays)
  43. return NULL;
  44. return &overlays[num];
  45. }
  46. EXPORT_SYMBOL(omap_dss_get_overlay);
  47. void dss_init_overlays(struct platform_device *pdev)
  48. {
  49. int i, r;
  50. num_overlays = dss_feat_get_num_ovls();
  51. overlays = kzalloc(sizeof(struct omap_overlay) * num_overlays,
  52. GFP_KERNEL);
  53. BUG_ON(overlays == NULL);
  54. for (i = 0; i < num_overlays; ++i) {
  55. struct omap_overlay *ovl = &overlays[i];
  56. switch (i) {
  57. case 0:
  58. ovl->name = "gfx";
  59. ovl->id = OMAP_DSS_GFX;
  60. break;
  61. case 1:
  62. ovl->name = "vid1";
  63. ovl->id = OMAP_DSS_VIDEO1;
  64. break;
  65. case 2:
  66. ovl->name = "vid2";
  67. ovl->id = OMAP_DSS_VIDEO2;
  68. break;
  69. case 3:
  70. ovl->name = "vid3";
  71. ovl->id = OMAP_DSS_VIDEO3;
  72. break;
  73. }
  74. ovl->is_enabled = &dss_ovl_is_enabled;
  75. ovl->enable = &dss_ovl_enable;
  76. ovl->disable = &dss_ovl_disable;
  77. ovl->set_manager = &dss_ovl_set_manager;
  78. ovl->unset_manager = &dss_ovl_unset_manager;
  79. ovl->set_overlay_info = &dss_ovl_set_info;
  80. ovl->get_overlay_info = &dss_ovl_get_info;
  81. ovl->wait_for_go = &dss_mgr_wait_for_go_ovl;
  82. ovl->caps = dss_feat_get_overlay_caps(ovl->id);
  83. ovl->supported_modes =
  84. dss_feat_get_supported_color_modes(ovl->id);
  85. r = dss_overlay_kobj_init(ovl, pdev);
  86. if (r)
  87. DSSERR("failed to create sysfs file\n");
  88. }
  89. }
  90. /* connect overlays to the new device, if not already connected. if force
  91. * selected, connect always. */
  92. void dss_recheck_connections(struct omap_dss_device *dssdev, bool force)
  93. {
  94. int i;
  95. struct omap_overlay_manager *lcd_mgr;
  96. struct omap_overlay_manager *tv_mgr;
  97. struct omap_overlay_manager *lcd2_mgr = NULL;
  98. struct omap_overlay_manager *lcd3_mgr = NULL;
  99. struct omap_overlay_manager *mgr = NULL;
  100. lcd_mgr = omap_dss_get_overlay_manager(OMAP_DSS_CHANNEL_LCD);
  101. tv_mgr = omap_dss_get_overlay_manager(OMAP_DSS_CHANNEL_DIGIT);
  102. if (dss_has_feature(FEAT_MGR_LCD3))
  103. lcd3_mgr = omap_dss_get_overlay_manager(OMAP_DSS_CHANNEL_LCD3);
  104. if (dss_has_feature(FEAT_MGR_LCD2))
  105. lcd2_mgr = omap_dss_get_overlay_manager(OMAP_DSS_CHANNEL_LCD2);
  106. if (dssdev->channel == OMAP_DSS_CHANNEL_LCD3) {
  107. if (!lcd3_mgr->device || force) {
  108. if (lcd3_mgr->device)
  109. lcd3_mgr->unset_device(lcd3_mgr);
  110. lcd3_mgr->set_device(lcd3_mgr, dssdev);
  111. mgr = lcd3_mgr;
  112. }
  113. } else if (dssdev->channel == OMAP_DSS_CHANNEL_LCD2) {
  114. if (!lcd2_mgr->device || force) {
  115. if (lcd2_mgr->device)
  116. lcd2_mgr->unset_device(lcd2_mgr);
  117. lcd2_mgr->set_device(lcd2_mgr, dssdev);
  118. mgr = lcd2_mgr;
  119. }
  120. } else if (dssdev->type != OMAP_DISPLAY_TYPE_VENC
  121. && dssdev->type != OMAP_DISPLAY_TYPE_HDMI) {
  122. if (!lcd_mgr->device || force) {
  123. if (lcd_mgr->device)
  124. lcd_mgr->unset_device(lcd_mgr);
  125. lcd_mgr->set_device(lcd_mgr, dssdev);
  126. mgr = lcd_mgr;
  127. }
  128. }
  129. if (dssdev->type == OMAP_DISPLAY_TYPE_VENC
  130. || dssdev->type == OMAP_DISPLAY_TYPE_HDMI) {
  131. if (!tv_mgr->device || force) {
  132. if (tv_mgr->device)
  133. tv_mgr->unset_device(tv_mgr);
  134. tv_mgr->set_device(tv_mgr, dssdev);
  135. mgr = tv_mgr;
  136. }
  137. }
  138. if (mgr) {
  139. dispc_runtime_get();
  140. for (i = 0; i < dss_feat_get_num_ovls(); i++) {
  141. struct omap_overlay *ovl;
  142. ovl = omap_dss_get_overlay(i);
  143. if (!ovl->manager || force) {
  144. if (ovl->manager)
  145. ovl->unset_manager(ovl);
  146. ovl->set_manager(ovl, mgr);
  147. }
  148. }
  149. dispc_runtime_put();
  150. }
  151. }
  152. void dss_uninit_overlays(struct platform_device *pdev)
  153. {
  154. int i;
  155. for (i = 0; i < num_overlays; ++i) {
  156. struct omap_overlay *ovl = &overlays[i];
  157. dss_overlay_kobj_uninit(ovl);
  158. }
  159. kfree(overlays);
  160. overlays = NULL;
  161. num_overlays = 0;
  162. }
  163. int dss_ovl_simple_check(struct omap_overlay *ovl,
  164. const struct omap_overlay_info *info)
  165. {
  166. if (info->paddr == 0) {
  167. DSSERR("check_overlay: paddr cannot be 0\n");
  168. return -EINVAL;
  169. }
  170. if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
  171. if (info->out_width != 0 && info->width != info->out_width) {
  172. DSSERR("check_overlay: overlay %d doesn't support "
  173. "scaling\n", ovl->id);
  174. return -EINVAL;
  175. }
  176. if (info->out_height != 0 && info->height != info->out_height) {
  177. DSSERR("check_overlay: overlay %d doesn't support "
  178. "scaling\n", ovl->id);
  179. return -EINVAL;
  180. }
  181. }
  182. if ((ovl->supported_modes & info->color_mode) == 0) {
  183. DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
  184. ovl->id, info->color_mode);
  185. return -EINVAL;
  186. }
  187. if (info->zorder >= omap_dss_get_num_overlays()) {
  188. DSSERR("check_overlay: zorder %d too high\n", info->zorder);
  189. return -EINVAL;
  190. }
  191. if (dss_feat_rotation_type_supported(info->rotation_type) == 0) {
  192. DSSERR("check_overlay: rotation type %d not supported\n",
  193. info->rotation_type);
  194. return -EINVAL;
  195. }
  196. return 0;
  197. }
  198. int dss_ovl_check(struct omap_overlay *ovl, struct omap_overlay_info *info,
  199. const struct omap_video_timings *mgr_timings)
  200. {
  201. u16 outw, outh;
  202. u16 dw, dh;
  203. dw = mgr_timings->x_res;
  204. dh = mgr_timings->y_res;
  205. if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
  206. outw = info->width;
  207. outh = info->height;
  208. } else {
  209. if (info->out_width == 0)
  210. outw = info->width;
  211. else
  212. outw = info->out_width;
  213. if (info->out_height == 0)
  214. outh = info->height;
  215. else
  216. outh = info->out_height;
  217. }
  218. if (dw < info->pos_x + outw) {
  219. DSSERR("overlay %d horizontally not inside the display area "
  220. "(%d + %d >= %d)\n",
  221. ovl->id, info->pos_x, outw, dw);
  222. return -EINVAL;
  223. }
  224. if (dh < info->pos_y + outh) {
  225. DSSERR("overlay %d vertically not inside the display area "
  226. "(%d + %d >= %d)\n",
  227. ovl->id, info->pos_y, outh, dh);
  228. return -EINVAL;
  229. }
  230. return 0;
  231. }
  232. /*
  233. * Checks if replication logic should be used. Only use when overlay is in
  234. * RGB12U or RGB16 mode, and video port width interface is 18bpp or 24bpp
  235. */
  236. bool dss_ovl_use_replication(struct dss_lcd_mgr_config config,
  237. enum omap_color_mode mode)
  238. {
  239. if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
  240. return false;
  241. return config.video_port_width > 16;
  242. }