overlay.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. struct omap_overlay_manager *mgr = NULL;
  95. int i;
  96. mgr = omap_dss_get_overlay_manager(dssdev->channel);
  97. if (!mgr->device || force) {
  98. if (mgr->device)
  99. mgr->unset_device(mgr);
  100. mgr->set_device(mgr, dssdev);
  101. }
  102. if (mgr) {
  103. dispc_runtime_get();
  104. for (i = 0; i < dss_feat_get_num_ovls(); i++) {
  105. struct omap_overlay *ovl;
  106. ovl = omap_dss_get_overlay(i);
  107. if (!ovl->manager || force) {
  108. if (ovl->manager)
  109. ovl->unset_manager(ovl);
  110. ovl->set_manager(ovl, mgr);
  111. }
  112. }
  113. dispc_runtime_put();
  114. }
  115. }
  116. void dss_uninit_overlays(struct platform_device *pdev)
  117. {
  118. int i;
  119. for (i = 0; i < num_overlays; ++i) {
  120. struct omap_overlay *ovl = &overlays[i];
  121. dss_overlay_kobj_uninit(ovl);
  122. }
  123. kfree(overlays);
  124. overlays = NULL;
  125. num_overlays = 0;
  126. }
  127. int dss_ovl_simple_check(struct omap_overlay *ovl,
  128. const struct omap_overlay_info *info)
  129. {
  130. if (info->paddr == 0) {
  131. DSSERR("check_overlay: paddr cannot be 0\n");
  132. return -EINVAL;
  133. }
  134. if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
  135. if (info->out_width != 0 && info->width != info->out_width) {
  136. DSSERR("check_overlay: overlay %d doesn't support "
  137. "scaling\n", ovl->id);
  138. return -EINVAL;
  139. }
  140. if (info->out_height != 0 && info->height != info->out_height) {
  141. DSSERR("check_overlay: overlay %d doesn't support "
  142. "scaling\n", ovl->id);
  143. return -EINVAL;
  144. }
  145. }
  146. if ((ovl->supported_modes & info->color_mode) == 0) {
  147. DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
  148. ovl->id, info->color_mode);
  149. return -EINVAL;
  150. }
  151. if (info->zorder >= omap_dss_get_num_overlays()) {
  152. DSSERR("check_overlay: zorder %d too high\n", info->zorder);
  153. return -EINVAL;
  154. }
  155. if (dss_feat_rotation_type_supported(info->rotation_type) == 0) {
  156. DSSERR("check_overlay: rotation type %d not supported\n",
  157. info->rotation_type);
  158. return -EINVAL;
  159. }
  160. return 0;
  161. }
  162. int dss_ovl_check(struct omap_overlay *ovl, struct omap_overlay_info *info,
  163. const struct omap_video_timings *mgr_timings)
  164. {
  165. u16 outw, outh;
  166. u16 dw, dh;
  167. dw = mgr_timings->x_res;
  168. dh = mgr_timings->y_res;
  169. if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
  170. outw = info->width;
  171. outh = info->height;
  172. } else {
  173. if (info->out_width == 0)
  174. outw = info->width;
  175. else
  176. outw = info->out_width;
  177. if (info->out_height == 0)
  178. outh = info->height;
  179. else
  180. outh = info->out_height;
  181. }
  182. if (dw < info->pos_x + outw) {
  183. DSSERR("overlay %d horizontally not inside the display area "
  184. "(%d + %d >= %d)\n",
  185. ovl->id, info->pos_x, outw, dw);
  186. return -EINVAL;
  187. }
  188. if (dh < info->pos_y + outh) {
  189. DSSERR("overlay %d vertically not inside the display area "
  190. "(%d + %d >= %d)\n",
  191. ovl->id, info->pos_y, outh, dh);
  192. return -EINVAL;
  193. }
  194. return 0;
  195. }
  196. /*
  197. * Checks if replication logic should be used. Only use when overlay is in
  198. * RGB12U or RGB16 mode, and video port width interface is 18bpp or 24bpp
  199. */
  200. bool dss_ovl_use_replication(struct dss_lcd_mgr_config config,
  201. enum omap_color_mode mode)
  202. {
  203. if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
  204. return false;
  205. return config.video_port_width > 16;
  206. }