manager.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * linux/drivers/video/omap2/dss/manager.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 "MANAGER"
  23. #include <linux/kernel.h>
  24. #include <linux/slab.h>
  25. #include <linux/module.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/jiffies.h>
  28. #include <video/omapdss.h>
  29. #include "dss.h"
  30. #include "dss_features.h"
  31. static int num_managers;
  32. static struct omap_overlay_manager *managers;
  33. int dss_init_overlay_managers(struct platform_device *pdev)
  34. {
  35. int i, r;
  36. num_managers = dss_feat_get_num_mgrs();
  37. managers = kzalloc(sizeof(struct omap_overlay_manager) * num_managers,
  38. GFP_KERNEL);
  39. BUG_ON(managers == NULL);
  40. for (i = 0; i < num_managers; ++i) {
  41. struct omap_overlay_manager *mgr = &managers[i];
  42. switch (i) {
  43. case 0:
  44. mgr->name = "lcd";
  45. mgr->id = OMAP_DSS_CHANNEL_LCD;
  46. break;
  47. case 1:
  48. mgr->name = "tv";
  49. mgr->id = OMAP_DSS_CHANNEL_DIGIT;
  50. break;
  51. case 2:
  52. mgr->name = "lcd2";
  53. mgr->id = OMAP_DSS_CHANNEL_LCD2;
  54. break;
  55. case 3:
  56. mgr->name = "lcd3";
  57. mgr->id = OMAP_DSS_CHANNEL_LCD3;
  58. break;
  59. }
  60. mgr->caps = 0;
  61. mgr->supported_displays =
  62. dss_feat_get_supported_displays(mgr->id);
  63. mgr->supported_outputs =
  64. dss_feat_get_supported_outputs(mgr->id);
  65. INIT_LIST_HEAD(&mgr->overlays);
  66. r = dss_manager_kobj_init(mgr, pdev);
  67. if (r)
  68. DSSERR("failed to create sysfs file\n");
  69. }
  70. return 0;
  71. }
  72. void dss_uninit_overlay_managers(struct platform_device *pdev)
  73. {
  74. int i;
  75. for (i = 0; i < num_managers; ++i) {
  76. struct omap_overlay_manager *mgr = &managers[i];
  77. dss_manager_kobj_uninit(mgr);
  78. }
  79. kfree(managers);
  80. managers = NULL;
  81. num_managers = 0;
  82. }
  83. int omap_dss_get_num_overlay_managers(void)
  84. {
  85. return num_managers;
  86. }
  87. EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
  88. struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
  89. {
  90. if (num >= num_managers)
  91. return NULL;
  92. return &managers[num];
  93. }
  94. EXPORT_SYMBOL(omap_dss_get_overlay_manager);
  95. int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
  96. const struct omap_overlay_manager_info *info)
  97. {
  98. if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
  99. /*
  100. * OMAP3 supports only graphics source transparency color key
  101. * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
  102. * Alpha Mode.
  103. */
  104. if (info->partial_alpha_enabled && info->trans_enabled
  105. && info->trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST) {
  106. DSSERR("check_manager: illegal transparency key\n");
  107. return -EINVAL;
  108. }
  109. }
  110. return 0;
  111. }
  112. static int dss_mgr_check_zorder(struct omap_overlay_manager *mgr,
  113. struct omap_overlay_info **overlay_infos)
  114. {
  115. struct omap_overlay *ovl1, *ovl2;
  116. struct omap_overlay_info *info1, *info2;
  117. list_for_each_entry(ovl1, &mgr->overlays, list) {
  118. info1 = overlay_infos[ovl1->id];
  119. if (info1 == NULL)
  120. continue;
  121. list_for_each_entry(ovl2, &mgr->overlays, list) {
  122. if (ovl1 == ovl2)
  123. continue;
  124. info2 = overlay_infos[ovl2->id];
  125. if (info2 == NULL)
  126. continue;
  127. if (info1->zorder == info2->zorder) {
  128. DSSERR("overlays %d and %d have the same "
  129. "zorder %d\n",
  130. ovl1->id, ovl2->id, info1->zorder);
  131. return -EINVAL;
  132. }
  133. }
  134. }
  135. return 0;
  136. }
  137. int dss_mgr_check_timings(struct omap_overlay_manager *mgr,
  138. const struct omap_video_timings *timings)
  139. {
  140. if (!dispc_mgr_timings_ok(mgr->id, timings)) {
  141. DSSERR("check_manager: invalid timings\n");
  142. return -EINVAL;
  143. }
  144. return 0;
  145. }
  146. static int dss_mgr_check_lcd_config(struct omap_overlay_manager *mgr,
  147. const struct dss_lcd_mgr_config *config)
  148. {
  149. struct dispc_clock_info cinfo = config->clock_info;
  150. int dl = config->video_port_width;
  151. bool stallmode = config->stallmode;
  152. bool fifohandcheck = config->fifohandcheck;
  153. if (cinfo.lck_div < 1 || cinfo.lck_div > 255)
  154. return -EINVAL;
  155. if (cinfo.pck_div < 1 || cinfo.pck_div > 255)
  156. return -EINVAL;
  157. if (dl != 12 && dl != 16 && dl != 18 && dl != 24)
  158. return -EINVAL;
  159. /* fifohandcheck should be used only with stallmode */
  160. if (stallmode == false && fifohandcheck == true)
  161. return -EINVAL;
  162. /*
  163. * io pad mode can be only checked by using dssdev connected to the
  164. * manager. Ignore checking these for now, add checks when manager
  165. * is capable of holding information related to the connected interface
  166. */
  167. return 0;
  168. }
  169. int dss_mgr_check(struct omap_overlay_manager *mgr,
  170. struct omap_overlay_manager_info *info,
  171. const struct omap_video_timings *mgr_timings,
  172. const struct dss_lcd_mgr_config *lcd_config,
  173. struct omap_overlay_info **overlay_infos)
  174. {
  175. struct omap_overlay *ovl;
  176. int r;
  177. if (dss_has_feature(FEAT_ALPHA_FREE_ZORDER)) {
  178. r = dss_mgr_check_zorder(mgr, overlay_infos);
  179. if (r)
  180. return r;
  181. }
  182. r = dss_mgr_check_timings(mgr, mgr_timings);
  183. if (r)
  184. return r;
  185. r = dss_mgr_check_lcd_config(mgr, lcd_config);
  186. if (r)
  187. return r;
  188. list_for_each_entry(ovl, &mgr->overlays, list) {
  189. struct omap_overlay_info *oi;
  190. int r;
  191. oi = overlay_infos[ovl->id];
  192. if (oi == NULL)
  193. continue;
  194. r = dss_ovl_check(ovl, oi, mgr_timings);
  195. if (r)
  196. return r;
  197. }
  198. return 0;
  199. }