overlay.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. static inline struct omap_dss_device *dss_ovl_get_device(struct omap_overlay *ovl)
  36. {
  37. return ovl->manager ?
  38. (ovl->manager->output ? ovl->manager->output->device : NULL) :
  39. NULL;
  40. }
  41. int omap_dss_get_num_overlays(void)
  42. {
  43. return num_overlays;
  44. }
  45. EXPORT_SYMBOL(omap_dss_get_num_overlays);
  46. struct omap_overlay *omap_dss_get_overlay(int num)
  47. {
  48. if (num >= num_overlays)
  49. return NULL;
  50. return &overlays[num];
  51. }
  52. EXPORT_SYMBOL(omap_dss_get_overlay);
  53. void dss_init_overlays(struct platform_device *pdev)
  54. {
  55. int i, r;
  56. num_overlays = dss_feat_get_num_ovls();
  57. overlays = kzalloc(sizeof(struct omap_overlay) * num_overlays,
  58. GFP_KERNEL);
  59. BUG_ON(overlays == NULL);
  60. for (i = 0; i < num_overlays; ++i) {
  61. struct omap_overlay *ovl = &overlays[i];
  62. switch (i) {
  63. case 0:
  64. ovl->name = "gfx";
  65. ovl->id = OMAP_DSS_GFX;
  66. break;
  67. case 1:
  68. ovl->name = "vid1";
  69. ovl->id = OMAP_DSS_VIDEO1;
  70. break;
  71. case 2:
  72. ovl->name = "vid2";
  73. ovl->id = OMAP_DSS_VIDEO2;
  74. break;
  75. case 3:
  76. ovl->name = "vid3";
  77. ovl->id = OMAP_DSS_VIDEO3;
  78. break;
  79. }
  80. ovl->is_enabled = &dss_ovl_is_enabled;
  81. ovl->enable = &dss_ovl_enable;
  82. ovl->disable = &dss_ovl_disable;
  83. ovl->set_manager = &dss_ovl_set_manager;
  84. ovl->unset_manager = &dss_ovl_unset_manager;
  85. ovl->set_overlay_info = &dss_ovl_set_info;
  86. ovl->get_overlay_info = &dss_ovl_get_info;
  87. ovl->wait_for_go = &dss_mgr_wait_for_go_ovl;
  88. ovl->get_device = &dss_ovl_get_device;
  89. ovl->caps = dss_feat_get_overlay_caps(ovl->id);
  90. ovl->supported_modes =
  91. dss_feat_get_supported_color_modes(ovl->id);
  92. r = dss_overlay_kobj_init(ovl, pdev);
  93. if (r)
  94. DSSERR("failed to create sysfs file\n");
  95. }
  96. }
  97. void dss_uninit_overlays(struct platform_device *pdev)
  98. {
  99. int i;
  100. for (i = 0; i < num_overlays; ++i) {
  101. struct omap_overlay *ovl = &overlays[i];
  102. dss_overlay_kobj_uninit(ovl);
  103. }
  104. kfree(overlays);
  105. overlays = NULL;
  106. num_overlays = 0;
  107. }
  108. int dss_ovl_simple_check(struct omap_overlay *ovl,
  109. const struct omap_overlay_info *info)
  110. {
  111. if (info->paddr == 0) {
  112. DSSERR("check_overlay: paddr cannot be 0\n");
  113. return -EINVAL;
  114. }
  115. if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
  116. if (info->out_width != 0 && info->width != info->out_width) {
  117. DSSERR("check_overlay: overlay %d doesn't support "
  118. "scaling\n", ovl->id);
  119. return -EINVAL;
  120. }
  121. if (info->out_height != 0 && info->height != info->out_height) {
  122. DSSERR("check_overlay: overlay %d doesn't support "
  123. "scaling\n", ovl->id);
  124. return -EINVAL;
  125. }
  126. }
  127. if ((ovl->supported_modes & info->color_mode) == 0) {
  128. DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
  129. ovl->id, info->color_mode);
  130. return -EINVAL;
  131. }
  132. if (info->zorder >= omap_dss_get_num_overlays()) {
  133. DSSERR("check_overlay: zorder %d too high\n", info->zorder);
  134. return -EINVAL;
  135. }
  136. if (dss_feat_rotation_type_supported(info->rotation_type) == 0) {
  137. DSSERR("check_overlay: rotation type %d not supported\n",
  138. info->rotation_type);
  139. return -EINVAL;
  140. }
  141. return 0;
  142. }
  143. int dss_ovl_check(struct omap_overlay *ovl, struct omap_overlay_info *info,
  144. const struct omap_video_timings *mgr_timings)
  145. {
  146. u16 outw, outh;
  147. u16 dw, dh;
  148. dw = mgr_timings->x_res;
  149. dh = mgr_timings->y_res;
  150. if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
  151. outw = info->width;
  152. outh = info->height;
  153. } else {
  154. if (info->out_width == 0)
  155. outw = info->width;
  156. else
  157. outw = info->out_width;
  158. if (info->out_height == 0)
  159. outh = info->height;
  160. else
  161. outh = info->out_height;
  162. }
  163. if (dw < info->pos_x + outw) {
  164. DSSERR("overlay %d horizontally not inside the display area "
  165. "(%d + %d >= %d)\n",
  166. ovl->id, info->pos_x, outw, dw);
  167. return -EINVAL;
  168. }
  169. if (dh < info->pos_y + outh) {
  170. DSSERR("overlay %d vertically not inside the display area "
  171. "(%d + %d >= %d)\n",
  172. ovl->id, info->pos_y, outh, dh);
  173. return -EINVAL;
  174. }
  175. return 0;
  176. }
  177. /*
  178. * Checks if replication logic should be used. Only use when overlay is in
  179. * RGB12U or RGB16 mode, and video port width interface is 18bpp or 24bpp
  180. */
  181. bool dss_ovl_use_replication(struct dss_lcd_mgr_config config,
  182. enum omap_color_mode mode)
  183. {
  184. if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
  185. return false;
  186. return config.video_port_width > 16;
  187. }