manager.c 6.6 KB

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