manager.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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/omapfb_dss.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(void)
  34. {
  35. int i;
  36. num_managers = dss_feat_get_num_mgrs();
  37. managers = kcalloc(num_managers, sizeof(struct omap_overlay_manager),
  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->supported_displays =
  61. dss_feat_get_supported_displays(mgr->id);
  62. mgr->supported_outputs =
  63. dss_feat_get_supported_outputs(mgr->id);
  64. INIT_LIST_HEAD(&mgr->overlays);
  65. }
  66. return 0;
  67. }
  68. int dss_init_overlay_managers_sysfs(struct platform_device *pdev)
  69. {
  70. int i, r;
  71. for (i = 0; i < num_managers; ++i) {
  72. struct omap_overlay_manager *mgr = &managers[i];
  73. r = dss_manager_kobj_init(mgr, pdev);
  74. if (r)
  75. DSSERR("failed to create sysfs file\n");
  76. }
  77. return 0;
  78. }
  79. void dss_uninit_overlay_managers(void)
  80. {
  81. kfree(managers);
  82. managers = NULL;
  83. num_managers = 0;
  84. }
  85. void dss_uninit_overlay_managers_sysfs(struct platform_device *pdev)
  86. {
  87. int i;
  88. for (i = 0; i < num_managers; ++i) {
  89. struct omap_overlay_manager *mgr = &managers[i];
  90. dss_manager_kobj_uninit(mgr);
  91. }
  92. }
  93. int omap_dss_get_num_overlay_managers(void)
  94. {
  95. return num_managers;
  96. }
  97. EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
  98. struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
  99. {
  100. if (num >= num_managers)
  101. return NULL;
  102. return &managers[num];
  103. }
  104. EXPORT_SYMBOL(omap_dss_get_overlay_manager);
  105. int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
  106. const struct omap_overlay_manager_info *info)
  107. {
  108. if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
  109. /*
  110. * OMAP3 supports only graphics source transparency color key
  111. * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
  112. * Alpha Mode.
  113. */
  114. if (info->partial_alpha_enabled && info->trans_enabled
  115. && info->trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST) {
  116. DSSERR("check_manager: illegal transparency key\n");
  117. return -EINVAL;
  118. }
  119. }
  120. return 0;
  121. }
  122. static int dss_mgr_check_zorder(struct omap_overlay_manager *mgr,
  123. struct omap_overlay_info **overlay_infos)
  124. {
  125. struct omap_overlay *ovl1, *ovl2;
  126. struct omap_overlay_info *info1, *info2;
  127. list_for_each_entry(ovl1, &mgr->overlays, list) {
  128. info1 = overlay_infos[ovl1->id];
  129. if (info1 == NULL)
  130. continue;
  131. list_for_each_entry(ovl2, &mgr->overlays, list) {
  132. if (ovl1 == ovl2)
  133. continue;
  134. info2 = overlay_infos[ovl2->id];
  135. if (info2 == NULL)
  136. continue;
  137. if (info1->zorder == info2->zorder) {
  138. DSSERR("overlays %d and %d have the same "
  139. "zorder %d\n",
  140. ovl1->id, ovl2->id, info1->zorder);
  141. return -EINVAL;
  142. }
  143. }
  144. }
  145. return 0;
  146. }
  147. int dss_mgr_check_timings(struct omap_overlay_manager *mgr,
  148. const struct omap_video_timings *timings)
  149. {
  150. if (!dispc_mgr_timings_ok(mgr->id, timings)) {
  151. DSSERR("check_manager: invalid timings\n");
  152. return -EINVAL;
  153. }
  154. return 0;
  155. }
  156. static int dss_mgr_check_lcd_config(struct omap_overlay_manager *mgr,
  157. const struct dss_lcd_mgr_config *config)
  158. {
  159. struct dispc_clock_info cinfo = config->clock_info;
  160. int dl = config->video_port_width;
  161. bool stallmode = config->stallmode;
  162. bool fifohandcheck = config->fifohandcheck;
  163. if (cinfo.lck_div < 1 || cinfo.lck_div > 255)
  164. return -EINVAL;
  165. if (cinfo.pck_div < 1 || cinfo.pck_div > 255)
  166. return -EINVAL;
  167. if (dl != 12 && dl != 16 && dl != 18 && dl != 24)
  168. return -EINVAL;
  169. /* fifohandcheck should be used only with stallmode */
  170. if (!stallmode && fifohandcheck)
  171. return -EINVAL;
  172. /*
  173. * io pad mode can be only checked by using dssdev connected to the
  174. * manager. Ignore checking these for now, add checks when manager
  175. * is capable of holding information related to the connected interface
  176. */
  177. return 0;
  178. }
  179. int dss_mgr_check(struct omap_overlay_manager *mgr,
  180. struct omap_overlay_manager_info *info,
  181. const struct omap_video_timings *mgr_timings,
  182. const struct dss_lcd_mgr_config *lcd_config,
  183. struct omap_overlay_info **overlay_infos)
  184. {
  185. struct omap_overlay *ovl;
  186. int r;
  187. if (dss_has_feature(FEAT_ALPHA_FREE_ZORDER)) {
  188. r = dss_mgr_check_zorder(mgr, overlay_infos);
  189. if (r)
  190. return r;
  191. }
  192. r = dss_mgr_check_timings(mgr, mgr_timings);
  193. if (r)
  194. return r;
  195. r = dss_mgr_check_lcd_config(mgr, lcd_config);
  196. if (r)
  197. return r;
  198. list_for_each_entry(ovl, &mgr->overlays, list) {
  199. struct omap_overlay_info *oi;
  200. int r;
  201. oi = overlay_infos[ovl->id];
  202. if (oi == NULL)
  203. continue;
  204. r = dss_ovl_check(ovl, oi, mgr_timings);
  205. if (r)
  206. return r;
  207. }
  208. return 0;
  209. }