overlay.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 (info->paddr == 0) {
  97. DSSERR("check_overlay: paddr cannot be 0\n");
  98. return -EINVAL;
  99. }
  100. if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
  101. if (info->out_width != 0 && info->width != info->out_width) {
  102. DSSERR("check_overlay: overlay %d doesn't support "
  103. "scaling\n", ovl->id);
  104. return -EINVAL;
  105. }
  106. if (info->out_height != 0 && info->height != info->out_height) {
  107. DSSERR("check_overlay: overlay %d doesn't support "
  108. "scaling\n", ovl->id);
  109. return -EINVAL;
  110. }
  111. }
  112. if ((ovl->supported_modes & info->color_mode) == 0) {
  113. DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
  114. ovl->id, info->color_mode);
  115. return -EINVAL;
  116. }
  117. if (info->zorder >= omap_dss_get_num_overlays()) {
  118. DSSERR("check_overlay: zorder %d too high\n", info->zorder);
  119. return -EINVAL;
  120. }
  121. if (dss_feat_rotation_type_supported(info->rotation_type) == 0) {
  122. DSSERR("check_overlay: rotation type %d not supported\n",
  123. info->rotation_type);
  124. return -EINVAL;
  125. }
  126. return 0;
  127. }
  128. int dss_ovl_check(struct omap_overlay *ovl, struct omap_overlay_info *info,
  129. const struct omap_video_timings *mgr_timings)
  130. {
  131. u16 outw, outh;
  132. u16 dw, dh;
  133. dw = mgr_timings->x_res;
  134. dh = mgr_timings->y_res;
  135. if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
  136. outw = info->width;
  137. outh = info->height;
  138. } else {
  139. if (info->out_width == 0)
  140. outw = info->width;
  141. else
  142. outw = info->out_width;
  143. if (info->out_height == 0)
  144. outh = info->height;
  145. else
  146. outh = info->out_height;
  147. }
  148. if (dw < info->pos_x + outw) {
  149. DSSERR("overlay %d horizontally not inside the display area "
  150. "(%d + %d >= %d)\n",
  151. ovl->id, info->pos_x, outw, dw);
  152. return -EINVAL;
  153. }
  154. if (dh < info->pos_y + outh) {
  155. DSSERR("overlay %d vertically not inside the display area "
  156. "(%d + %d >= %d)\n",
  157. ovl->id, info->pos_y, outh, dh);
  158. return -EINVAL;
  159. }
  160. return 0;
  161. }
  162. /*
  163. * Checks if replication logic should be used. Only use when overlay is in
  164. * RGB12U or RGB16 mode, and video port width interface is 18bpp or 24bpp
  165. */
  166. bool dss_ovl_use_replication(struct dss_lcd_mgr_config config,
  167. enum omap_color_mode mode)
  168. {
  169. if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
  170. return false;
  171. return config.video_port_width > 16;
  172. }