overlay.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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->caps = dss_feat_get_overlay_caps(ovl->id);
  75. ovl->supported_modes =
  76. dss_feat_get_supported_color_modes(ovl->id);
  77. r = dss_overlay_kobj_init(ovl, pdev);
  78. if (r)
  79. DSSERR("failed to create sysfs file\n");
  80. }
  81. }
  82. void dss_uninit_overlays(struct platform_device *pdev)
  83. {
  84. int i;
  85. for (i = 0; i < num_overlays; ++i) {
  86. struct omap_overlay *ovl = &overlays[i];
  87. dss_overlay_kobj_uninit(ovl);
  88. }
  89. kfree(overlays);
  90. overlays = NULL;
  91. num_overlays = 0;
  92. }
  93. int dss_ovl_simple_check(struct omap_overlay *ovl,
  94. const struct omap_overlay_info *info)
  95. {
  96. if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
  97. if (info->out_width != 0 && info->width != info->out_width) {
  98. DSSERR("check_overlay: overlay %d doesn't support "
  99. "scaling\n", ovl->id);
  100. return -EINVAL;
  101. }
  102. if (info->out_height != 0 && info->height != info->out_height) {
  103. DSSERR("check_overlay: overlay %d doesn't support "
  104. "scaling\n", ovl->id);
  105. return -EINVAL;
  106. }
  107. }
  108. if ((ovl->supported_modes & info->color_mode) == 0) {
  109. DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
  110. ovl->id, info->color_mode);
  111. return -EINVAL;
  112. }
  113. if (info->zorder >= omap_dss_get_num_overlays()) {
  114. DSSERR("check_overlay: zorder %d too high\n", info->zorder);
  115. return -EINVAL;
  116. }
  117. if (dss_feat_rotation_type_supported(info->rotation_type) == 0) {
  118. DSSERR("check_overlay: rotation type %d not supported\n",
  119. info->rotation_type);
  120. return -EINVAL;
  121. }
  122. return 0;
  123. }
  124. int dss_ovl_check(struct omap_overlay *ovl, struct omap_overlay_info *info,
  125. const struct omap_video_timings *mgr_timings)
  126. {
  127. u16 outw, outh;
  128. u16 dw, dh;
  129. dw = mgr_timings->x_res;
  130. dh = mgr_timings->y_res;
  131. if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
  132. outw = info->width;
  133. outh = info->height;
  134. } else {
  135. if (info->out_width == 0)
  136. outw = info->width;
  137. else
  138. outw = info->out_width;
  139. if (info->out_height == 0)
  140. outh = info->height;
  141. else
  142. outh = info->out_height;
  143. }
  144. if (dw < info->pos_x + outw) {
  145. DSSERR("overlay %d horizontally not inside the display area "
  146. "(%d + %d >= %d)\n",
  147. ovl->id, info->pos_x, outw, dw);
  148. return -EINVAL;
  149. }
  150. if (dh < info->pos_y + outh) {
  151. DSSERR("overlay %d vertically not inside the display area "
  152. "(%d + %d >= %d)\n",
  153. ovl->id, info->pos_y, outh, dh);
  154. return -EINVAL;
  155. }
  156. return 0;
  157. }
  158. /*
  159. * Checks if replication logic should be used. Only use when overlay is in
  160. * RGB12U or RGB16 mode, and video port width interface is 18bpp or 24bpp
  161. */
  162. bool dss_ovl_use_replication(struct dss_lcd_mgr_config config,
  163. enum omap_color_mode mode)
  164. {
  165. if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
  166. return false;
  167. return config.video_port_width > 16;
  168. }