manager.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. static inline struct omap_dss_device *dss_mgr_get_device(struct omap_overlay_manager *mgr)
  34. {
  35. return mgr->output ? mgr->output->device : NULL;
  36. }
  37. static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
  38. {
  39. unsigned long timeout = msecs_to_jiffies(500);
  40. struct omap_dss_device *dssdev = mgr->get_device(mgr);
  41. u32 irq;
  42. int r;
  43. r = dispc_runtime_get();
  44. if (r)
  45. return r;
  46. if (dssdev->type == OMAP_DISPLAY_TYPE_VENC)
  47. irq = DISPC_IRQ_EVSYNC_ODD;
  48. else if (dssdev->type == OMAP_DISPLAY_TYPE_HDMI)
  49. irq = DISPC_IRQ_EVSYNC_EVEN;
  50. else
  51. irq = dispc_mgr_get_vsync_irq(mgr->id);
  52. r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
  53. dispc_runtime_put();
  54. return r;
  55. }
  56. int dss_init_overlay_managers(struct platform_device *pdev)
  57. {
  58. int i, r;
  59. num_managers = dss_feat_get_num_mgrs();
  60. managers = kzalloc(sizeof(struct omap_overlay_manager) * num_managers,
  61. GFP_KERNEL);
  62. BUG_ON(managers == NULL);
  63. for (i = 0; i < num_managers; ++i) {
  64. struct omap_overlay_manager *mgr = &managers[i];
  65. switch (i) {
  66. case 0:
  67. mgr->name = "lcd";
  68. mgr->id = OMAP_DSS_CHANNEL_LCD;
  69. break;
  70. case 1:
  71. mgr->name = "tv";
  72. mgr->id = OMAP_DSS_CHANNEL_DIGIT;
  73. break;
  74. case 2:
  75. mgr->name = "lcd2";
  76. mgr->id = OMAP_DSS_CHANNEL_LCD2;
  77. break;
  78. case 3:
  79. mgr->name = "lcd3";
  80. mgr->id = OMAP_DSS_CHANNEL_LCD3;
  81. break;
  82. }
  83. mgr->set_device = &dss_mgr_set_device;
  84. mgr->unset_device = &dss_mgr_unset_device;
  85. mgr->set_output = &dss_mgr_set_output;
  86. mgr->unset_output = &dss_mgr_unset_output;
  87. mgr->apply = &omap_dss_mgr_apply;
  88. mgr->set_manager_info = &dss_mgr_set_info;
  89. mgr->get_manager_info = &dss_mgr_get_info;
  90. mgr->wait_for_go = &dss_mgr_wait_for_go;
  91. mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
  92. mgr->get_device = &dss_mgr_get_device;
  93. mgr->caps = 0;
  94. mgr->supported_displays =
  95. dss_feat_get_supported_displays(mgr->id);
  96. mgr->supported_outputs =
  97. dss_feat_get_supported_outputs(mgr->id);
  98. INIT_LIST_HEAD(&mgr->overlays);
  99. r = dss_manager_kobj_init(mgr, pdev);
  100. if (r)
  101. DSSERR("failed to create sysfs file\n");
  102. }
  103. return 0;
  104. }
  105. void dss_uninit_overlay_managers(struct platform_device *pdev)
  106. {
  107. int i;
  108. for (i = 0; i < num_managers; ++i) {
  109. struct omap_overlay_manager *mgr = &managers[i];
  110. dss_manager_kobj_uninit(mgr);
  111. }
  112. kfree(managers);
  113. managers = NULL;
  114. num_managers = 0;
  115. }
  116. int omap_dss_get_num_overlay_managers(void)
  117. {
  118. return num_managers;
  119. }
  120. EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
  121. struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
  122. {
  123. if (num >= num_managers)
  124. return NULL;
  125. return &managers[num];
  126. }
  127. EXPORT_SYMBOL(omap_dss_get_overlay_manager);
  128. int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
  129. const struct omap_overlay_manager_info *info)
  130. {
  131. if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
  132. /*
  133. * OMAP3 supports only graphics source transparency color key
  134. * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
  135. * Alpha Mode.
  136. */
  137. if (info->partial_alpha_enabled && info->trans_enabled
  138. && info->trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST) {
  139. DSSERR("check_manager: illegal transparency key\n");
  140. return -EINVAL;
  141. }
  142. }
  143. return 0;
  144. }
  145. static int dss_mgr_check_zorder(struct omap_overlay_manager *mgr,
  146. struct omap_overlay_info **overlay_infos)
  147. {
  148. struct omap_overlay *ovl1, *ovl2;
  149. struct omap_overlay_info *info1, *info2;
  150. list_for_each_entry(ovl1, &mgr->overlays, list) {
  151. info1 = overlay_infos[ovl1->id];
  152. if (info1 == NULL)
  153. continue;
  154. list_for_each_entry(ovl2, &mgr->overlays, list) {
  155. if (ovl1 == ovl2)
  156. continue;
  157. info2 = overlay_infos[ovl2->id];
  158. if (info2 == NULL)
  159. continue;
  160. if (info1->zorder == info2->zorder) {
  161. DSSERR("overlays %d and %d have the same "
  162. "zorder %d\n",
  163. ovl1->id, ovl2->id, info1->zorder);
  164. return -EINVAL;
  165. }
  166. }
  167. }
  168. return 0;
  169. }
  170. int dss_mgr_check_timings(struct omap_overlay_manager *mgr,
  171. const struct omap_video_timings *timings)
  172. {
  173. if (!dispc_mgr_timings_ok(mgr->id, timings)) {
  174. DSSERR("check_manager: invalid timings\n");
  175. return -EINVAL;
  176. }
  177. return 0;
  178. }
  179. static int dss_mgr_check_lcd_config(struct omap_overlay_manager *mgr,
  180. const struct dss_lcd_mgr_config *config)
  181. {
  182. struct dispc_clock_info cinfo = config->clock_info;
  183. int dl = config->video_port_width;
  184. bool stallmode = config->stallmode;
  185. bool fifohandcheck = config->fifohandcheck;
  186. if (cinfo.lck_div < 1 || cinfo.lck_div > 255)
  187. return -EINVAL;
  188. if (cinfo.pck_div < 1 || cinfo.pck_div > 255)
  189. return -EINVAL;
  190. if (dl != 12 && dl != 16 && dl != 18 && dl != 24)
  191. return -EINVAL;
  192. /* fifohandcheck should be used only with stallmode */
  193. if (stallmode == false && fifohandcheck == true)
  194. return -EINVAL;
  195. /*
  196. * io pad mode can be only checked by using dssdev connected to the
  197. * manager. Ignore checking these for now, add checks when manager
  198. * is capable of holding information related to the connected interface
  199. */
  200. return 0;
  201. }
  202. int dss_mgr_check(struct omap_overlay_manager *mgr,
  203. struct omap_overlay_manager_info *info,
  204. const struct omap_video_timings *mgr_timings,
  205. const struct dss_lcd_mgr_config *lcd_config,
  206. struct omap_overlay_info **overlay_infos)
  207. {
  208. struct omap_overlay *ovl;
  209. int r;
  210. if (dss_has_feature(FEAT_ALPHA_FREE_ZORDER)) {
  211. r = dss_mgr_check_zorder(mgr, overlay_infos);
  212. if (r)
  213. return r;
  214. }
  215. r = dss_mgr_check_timings(mgr, mgr_timings);
  216. if (r)
  217. return r;
  218. r = dss_mgr_check_lcd_config(mgr, lcd_config);
  219. if (r)
  220. return r;
  221. list_for_each_entry(ovl, &mgr->overlays, list) {
  222. struct omap_overlay_info *oi;
  223. int r;
  224. oi = overlay_infos[ovl->id];
  225. if (oi == NULL)
  226. continue;
  227. r = dss_ovl_check(ovl, oi, mgr_timings);
  228. if (r)
  229. return r;
  230. }
  231. return 0;
  232. }