manager.c 6.3 KB

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