manager.c 5.8 KB

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