manager.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645
  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/spinlock.h>
  28. #include <linux/jiffies.h>
  29. #include <video/omapdss.h>
  30. #include <plat/cpu.h>
  31. #include "dss.h"
  32. #include "dss_features.h"
  33. static int num_managers;
  34. static struct list_head manager_list;
  35. static ssize_t manager_name_show(struct omap_overlay_manager *mgr, char *buf)
  36. {
  37. return snprintf(buf, PAGE_SIZE, "%s\n", mgr->name);
  38. }
  39. static ssize_t manager_display_show(struct omap_overlay_manager *mgr, char *buf)
  40. {
  41. return snprintf(buf, PAGE_SIZE, "%s\n",
  42. mgr->device ? mgr->device->name : "<none>");
  43. }
  44. static ssize_t manager_display_store(struct omap_overlay_manager *mgr,
  45. const char *buf, size_t size)
  46. {
  47. int r = 0;
  48. size_t len = size;
  49. struct omap_dss_device *dssdev = NULL;
  50. int match(struct omap_dss_device *dssdev, void *data)
  51. {
  52. const char *str = data;
  53. return sysfs_streq(dssdev->name, str);
  54. }
  55. if (buf[size-1] == '\n')
  56. --len;
  57. if (len > 0)
  58. dssdev = omap_dss_find_device((void *)buf, match);
  59. if (len > 0 && dssdev == NULL)
  60. return -EINVAL;
  61. if (dssdev)
  62. DSSDBG("display %s found\n", dssdev->name);
  63. if (mgr->device) {
  64. r = mgr->unset_device(mgr);
  65. if (r) {
  66. DSSERR("failed to unset display\n");
  67. goto put_device;
  68. }
  69. }
  70. if (dssdev) {
  71. r = mgr->set_device(mgr, dssdev);
  72. if (r) {
  73. DSSERR("failed to set manager\n");
  74. goto put_device;
  75. }
  76. r = mgr->apply(mgr);
  77. if (r) {
  78. DSSERR("failed to apply dispc config\n");
  79. goto put_device;
  80. }
  81. }
  82. put_device:
  83. if (dssdev)
  84. omap_dss_put_device(dssdev);
  85. return r ? r : size;
  86. }
  87. static ssize_t manager_default_color_show(struct omap_overlay_manager *mgr,
  88. char *buf)
  89. {
  90. return snprintf(buf, PAGE_SIZE, "%#x\n", mgr->info.default_color);
  91. }
  92. static ssize_t manager_default_color_store(struct omap_overlay_manager *mgr,
  93. const char *buf, size_t size)
  94. {
  95. struct omap_overlay_manager_info info;
  96. u32 color;
  97. int r;
  98. r = kstrtouint(buf, 0, &color);
  99. if (r)
  100. return r;
  101. mgr->get_manager_info(mgr, &info);
  102. info.default_color = color;
  103. r = mgr->set_manager_info(mgr, &info);
  104. if (r)
  105. return r;
  106. r = mgr->apply(mgr);
  107. if (r)
  108. return r;
  109. return size;
  110. }
  111. static const char *trans_key_type_str[] = {
  112. "gfx-destination",
  113. "video-source",
  114. };
  115. static ssize_t manager_trans_key_type_show(struct omap_overlay_manager *mgr,
  116. char *buf)
  117. {
  118. enum omap_dss_trans_key_type key_type;
  119. key_type = mgr->info.trans_key_type;
  120. BUG_ON(key_type >= ARRAY_SIZE(trans_key_type_str));
  121. return snprintf(buf, PAGE_SIZE, "%s\n", trans_key_type_str[key_type]);
  122. }
  123. static ssize_t manager_trans_key_type_store(struct omap_overlay_manager *mgr,
  124. const char *buf, size_t size)
  125. {
  126. enum omap_dss_trans_key_type key_type;
  127. struct omap_overlay_manager_info info;
  128. int r;
  129. for (key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
  130. key_type < ARRAY_SIZE(trans_key_type_str); key_type++) {
  131. if (sysfs_streq(buf, trans_key_type_str[key_type]))
  132. break;
  133. }
  134. if (key_type == ARRAY_SIZE(trans_key_type_str))
  135. return -EINVAL;
  136. mgr->get_manager_info(mgr, &info);
  137. info.trans_key_type = key_type;
  138. r = mgr->set_manager_info(mgr, &info);
  139. if (r)
  140. return r;
  141. r = mgr->apply(mgr);
  142. if (r)
  143. return r;
  144. return size;
  145. }
  146. static ssize_t manager_trans_key_value_show(struct omap_overlay_manager *mgr,
  147. char *buf)
  148. {
  149. return snprintf(buf, PAGE_SIZE, "%#x\n", mgr->info.trans_key);
  150. }
  151. static ssize_t manager_trans_key_value_store(struct omap_overlay_manager *mgr,
  152. const char *buf, size_t size)
  153. {
  154. struct omap_overlay_manager_info info;
  155. u32 key_value;
  156. int r;
  157. r = kstrtouint(buf, 0, &key_value);
  158. if (r)
  159. return r;
  160. mgr->get_manager_info(mgr, &info);
  161. info.trans_key = key_value;
  162. r = mgr->set_manager_info(mgr, &info);
  163. if (r)
  164. return r;
  165. r = mgr->apply(mgr);
  166. if (r)
  167. return r;
  168. return size;
  169. }
  170. static ssize_t manager_trans_key_enabled_show(struct omap_overlay_manager *mgr,
  171. char *buf)
  172. {
  173. return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_enabled);
  174. }
  175. static ssize_t manager_trans_key_enabled_store(struct omap_overlay_manager *mgr,
  176. const char *buf, size_t size)
  177. {
  178. struct omap_overlay_manager_info info;
  179. bool enable;
  180. int r;
  181. r = strtobool(buf, &enable);
  182. if (r)
  183. return r;
  184. mgr->get_manager_info(mgr, &info);
  185. info.trans_enabled = enable;
  186. r = mgr->set_manager_info(mgr, &info);
  187. if (r)
  188. return r;
  189. r = mgr->apply(mgr);
  190. if (r)
  191. return r;
  192. return size;
  193. }
  194. static ssize_t manager_alpha_blending_enabled_show(
  195. struct omap_overlay_manager *mgr, char *buf)
  196. {
  197. WARN_ON(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER));
  198. return snprintf(buf, PAGE_SIZE, "%d\n",
  199. mgr->info.partial_alpha_enabled);
  200. }
  201. static ssize_t manager_alpha_blending_enabled_store(
  202. struct omap_overlay_manager *mgr,
  203. const char *buf, size_t size)
  204. {
  205. struct omap_overlay_manager_info info;
  206. bool enable;
  207. int r;
  208. WARN_ON(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER));
  209. r = strtobool(buf, &enable);
  210. if (r)
  211. return r;
  212. mgr->get_manager_info(mgr, &info);
  213. info.partial_alpha_enabled = enable;
  214. r = mgr->set_manager_info(mgr, &info);
  215. if (r)
  216. return r;
  217. r = mgr->apply(mgr);
  218. if (r)
  219. return r;
  220. return size;
  221. }
  222. static ssize_t manager_cpr_enable_show(struct omap_overlay_manager *mgr,
  223. char *buf)
  224. {
  225. return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.cpr_enable);
  226. }
  227. static ssize_t manager_cpr_enable_store(struct omap_overlay_manager *mgr,
  228. const char *buf, size_t size)
  229. {
  230. struct omap_overlay_manager_info info;
  231. int r;
  232. bool enable;
  233. if (!dss_has_feature(FEAT_CPR))
  234. return -ENODEV;
  235. r = strtobool(buf, &enable);
  236. if (r)
  237. return r;
  238. mgr->get_manager_info(mgr, &info);
  239. if (info.cpr_enable == enable)
  240. return size;
  241. info.cpr_enable = enable;
  242. r = mgr->set_manager_info(mgr, &info);
  243. if (r)
  244. return r;
  245. r = mgr->apply(mgr);
  246. if (r)
  247. return r;
  248. return size;
  249. }
  250. static ssize_t manager_cpr_coef_show(struct omap_overlay_manager *mgr,
  251. char *buf)
  252. {
  253. struct omap_overlay_manager_info info;
  254. mgr->get_manager_info(mgr, &info);
  255. return snprintf(buf, PAGE_SIZE,
  256. "%d %d %d %d %d %d %d %d %d\n",
  257. info.cpr_coefs.rr,
  258. info.cpr_coefs.rg,
  259. info.cpr_coefs.rb,
  260. info.cpr_coefs.gr,
  261. info.cpr_coefs.gg,
  262. info.cpr_coefs.gb,
  263. info.cpr_coefs.br,
  264. info.cpr_coefs.bg,
  265. info.cpr_coefs.bb);
  266. }
  267. static ssize_t manager_cpr_coef_store(struct omap_overlay_manager *mgr,
  268. const char *buf, size_t size)
  269. {
  270. struct omap_overlay_manager_info info;
  271. struct omap_dss_cpr_coefs coefs;
  272. int r, i;
  273. s16 *arr;
  274. if (!dss_has_feature(FEAT_CPR))
  275. return -ENODEV;
  276. if (sscanf(buf, "%hd %hd %hd %hd %hd %hd %hd %hd %hd",
  277. &coefs.rr, &coefs.rg, &coefs.rb,
  278. &coefs.gr, &coefs.gg, &coefs.gb,
  279. &coefs.br, &coefs.bg, &coefs.bb) != 9)
  280. return -EINVAL;
  281. arr = (s16[]){ coefs.rr, coefs.rg, coefs.rb,
  282. coefs.gr, coefs.gg, coefs.gb,
  283. coefs.br, coefs.bg, coefs.bb };
  284. for (i = 0; i < 9; ++i) {
  285. if (arr[i] < -512 || arr[i] > 511)
  286. return -EINVAL;
  287. }
  288. mgr->get_manager_info(mgr, &info);
  289. info.cpr_coefs = coefs;
  290. r = mgr->set_manager_info(mgr, &info);
  291. if (r)
  292. return r;
  293. r = mgr->apply(mgr);
  294. if (r)
  295. return r;
  296. return size;
  297. }
  298. struct manager_attribute {
  299. struct attribute attr;
  300. ssize_t (*show)(struct omap_overlay_manager *, char *);
  301. ssize_t (*store)(struct omap_overlay_manager *, const char *, size_t);
  302. };
  303. #define MANAGER_ATTR(_name, _mode, _show, _store) \
  304. struct manager_attribute manager_attr_##_name = \
  305. __ATTR(_name, _mode, _show, _store)
  306. static MANAGER_ATTR(name, S_IRUGO, manager_name_show, NULL);
  307. static MANAGER_ATTR(display, S_IRUGO|S_IWUSR,
  308. manager_display_show, manager_display_store);
  309. static MANAGER_ATTR(default_color, S_IRUGO|S_IWUSR,
  310. manager_default_color_show, manager_default_color_store);
  311. static MANAGER_ATTR(trans_key_type, S_IRUGO|S_IWUSR,
  312. manager_trans_key_type_show, manager_trans_key_type_store);
  313. static MANAGER_ATTR(trans_key_value, S_IRUGO|S_IWUSR,
  314. manager_trans_key_value_show, manager_trans_key_value_store);
  315. static MANAGER_ATTR(trans_key_enabled, S_IRUGO|S_IWUSR,
  316. manager_trans_key_enabled_show,
  317. manager_trans_key_enabled_store);
  318. static MANAGER_ATTR(alpha_blending_enabled, S_IRUGO|S_IWUSR,
  319. manager_alpha_blending_enabled_show,
  320. manager_alpha_blending_enabled_store);
  321. static MANAGER_ATTR(cpr_enable, S_IRUGO|S_IWUSR,
  322. manager_cpr_enable_show,
  323. manager_cpr_enable_store);
  324. static MANAGER_ATTR(cpr_coef, S_IRUGO|S_IWUSR,
  325. manager_cpr_coef_show,
  326. manager_cpr_coef_store);
  327. static struct attribute *manager_sysfs_attrs[] = {
  328. &manager_attr_name.attr,
  329. &manager_attr_display.attr,
  330. &manager_attr_default_color.attr,
  331. &manager_attr_trans_key_type.attr,
  332. &manager_attr_trans_key_value.attr,
  333. &manager_attr_trans_key_enabled.attr,
  334. &manager_attr_alpha_blending_enabled.attr,
  335. &manager_attr_cpr_enable.attr,
  336. &manager_attr_cpr_coef.attr,
  337. NULL
  338. };
  339. static ssize_t manager_attr_show(struct kobject *kobj, struct attribute *attr,
  340. char *buf)
  341. {
  342. struct omap_overlay_manager *manager;
  343. struct manager_attribute *manager_attr;
  344. manager = container_of(kobj, struct omap_overlay_manager, kobj);
  345. manager_attr = container_of(attr, struct manager_attribute, attr);
  346. if (!manager_attr->show)
  347. return -ENOENT;
  348. return manager_attr->show(manager, buf);
  349. }
  350. static ssize_t manager_attr_store(struct kobject *kobj, struct attribute *attr,
  351. const char *buf, size_t size)
  352. {
  353. struct omap_overlay_manager *manager;
  354. struct manager_attribute *manager_attr;
  355. manager = container_of(kobj, struct omap_overlay_manager, kobj);
  356. manager_attr = container_of(attr, struct manager_attribute, attr);
  357. if (!manager_attr->store)
  358. return -ENOENT;
  359. return manager_attr->store(manager, buf, size);
  360. }
  361. static const struct sysfs_ops manager_sysfs_ops = {
  362. .show = manager_attr_show,
  363. .store = manager_attr_store,
  364. };
  365. static struct kobj_type manager_ktype = {
  366. .sysfs_ops = &manager_sysfs_ops,
  367. .default_attrs = manager_sysfs_attrs,
  368. };
  369. /*
  370. * We have 4 levels of cache for the dispc settings. First two are in SW and
  371. * the latter two in HW.
  372. *
  373. * +--------------------+
  374. * |overlay/manager_info|
  375. * +--------------------+
  376. * v
  377. * apply()
  378. * v
  379. * +--------------------+
  380. * | dss_cache |
  381. * +--------------------+
  382. * v
  383. * configure()
  384. * v
  385. * +--------------------+
  386. * | shadow registers |
  387. * +--------------------+
  388. * v
  389. * VFP or lcd/digit_enable
  390. * v
  391. * +--------------------+
  392. * | registers |
  393. * +--------------------+
  394. */
  395. struct overlay_cache_data {
  396. /* If true, cache changed, but not written to shadow registers. Set
  397. * in apply(), cleared when registers written. */
  398. bool dirty;
  399. /* If true, shadow registers contain changed values not yet in real
  400. * registers. Set when writing to shadow registers, cleared at
  401. * VSYNC/EVSYNC */
  402. bool shadow_dirty;
  403. bool enabled;
  404. struct omap_overlay_info info;
  405. enum omap_channel channel;
  406. bool replication;
  407. bool ilace;
  408. u32 fifo_low;
  409. u32 fifo_high;
  410. };
  411. struct manager_cache_data {
  412. /* If true, cache changed, but not written to shadow registers. Set
  413. * in apply(), cleared when registers written. */
  414. bool dirty;
  415. /* If true, shadow registers contain changed values not yet in real
  416. * registers. Set when writing to shadow registers, cleared at
  417. * VSYNC/EVSYNC */
  418. bool shadow_dirty;
  419. struct omap_overlay_manager_info info;
  420. bool manual_update;
  421. bool do_manual_update;
  422. /* manual update region */
  423. u16 x, y, w, h;
  424. /* enlarge the update area if the update area contains scaled
  425. * overlays */
  426. bool enlarge_update_area;
  427. };
  428. static struct {
  429. spinlock_t lock;
  430. struct overlay_cache_data overlay_cache[MAX_DSS_OVERLAYS];
  431. struct manager_cache_data manager_cache[MAX_DSS_MANAGERS];
  432. bool irq_enabled;
  433. } dss_cache;
  434. static int omap_dss_set_device(struct omap_overlay_manager *mgr,
  435. struct omap_dss_device *dssdev)
  436. {
  437. int i;
  438. int r;
  439. if (dssdev->manager) {
  440. DSSERR("display '%s' already has a manager '%s'\n",
  441. dssdev->name, dssdev->manager->name);
  442. return -EINVAL;
  443. }
  444. if ((mgr->supported_displays & dssdev->type) == 0) {
  445. DSSERR("display '%s' does not support manager '%s'\n",
  446. dssdev->name, mgr->name);
  447. return -EINVAL;
  448. }
  449. for (i = 0; i < mgr->num_overlays; i++) {
  450. struct omap_overlay *ovl = mgr->overlays[i];
  451. if (ovl->manager != mgr || !ovl->info.enabled)
  452. continue;
  453. r = dss_check_overlay(ovl, dssdev);
  454. if (r)
  455. return r;
  456. }
  457. dssdev->manager = mgr;
  458. mgr->device = dssdev;
  459. mgr->device_changed = true;
  460. return 0;
  461. }
  462. static int omap_dss_unset_device(struct omap_overlay_manager *mgr)
  463. {
  464. if (!mgr->device) {
  465. DSSERR("failed to unset display, display not set.\n");
  466. return -EINVAL;
  467. }
  468. /*
  469. * Don't allow currently enabled displays to have the overlay manager
  470. * pulled out from underneath them
  471. */
  472. if (mgr->device->state != OMAP_DSS_DISPLAY_DISABLED)
  473. return -EINVAL;
  474. mgr->device->manager = NULL;
  475. mgr->device = NULL;
  476. mgr->device_changed = true;
  477. return 0;
  478. }
  479. static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
  480. {
  481. unsigned long timeout = msecs_to_jiffies(500);
  482. u32 irq;
  483. if (mgr->device->type == OMAP_DISPLAY_TYPE_VENC) {
  484. irq = DISPC_IRQ_EVSYNC_ODD;
  485. } else if (mgr->device->type == OMAP_DISPLAY_TYPE_HDMI) {
  486. irq = DISPC_IRQ_EVSYNC_EVEN;
  487. } else {
  488. if (mgr->id == OMAP_DSS_CHANNEL_LCD)
  489. irq = DISPC_IRQ_VSYNC;
  490. else
  491. irq = DISPC_IRQ_VSYNC2;
  492. }
  493. return omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
  494. }
  495. static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
  496. {
  497. unsigned long timeout = msecs_to_jiffies(500);
  498. struct manager_cache_data *mc;
  499. u32 irq;
  500. int r;
  501. int i;
  502. struct omap_dss_device *dssdev = mgr->device;
  503. if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  504. return 0;
  505. if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE)
  506. return 0;
  507. if (dssdev->type == OMAP_DISPLAY_TYPE_VENC
  508. || dssdev->type == OMAP_DISPLAY_TYPE_HDMI) {
  509. irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
  510. } else {
  511. irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
  512. DISPC_IRQ_VSYNC : DISPC_IRQ_VSYNC2;
  513. }
  514. mc = &dss_cache.manager_cache[mgr->id];
  515. i = 0;
  516. while (1) {
  517. unsigned long flags;
  518. bool shadow_dirty, dirty;
  519. spin_lock_irqsave(&dss_cache.lock, flags);
  520. dirty = mc->dirty;
  521. shadow_dirty = mc->shadow_dirty;
  522. spin_unlock_irqrestore(&dss_cache.lock, flags);
  523. if (!dirty && !shadow_dirty) {
  524. r = 0;
  525. break;
  526. }
  527. /* 4 iterations is the worst case:
  528. * 1 - initial iteration, dirty = true (between VFP and VSYNC)
  529. * 2 - first VSYNC, dirty = true
  530. * 3 - dirty = false, shadow_dirty = true
  531. * 4 - shadow_dirty = false */
  532. if (i++ == 3) {
  533. DSSERR("mgr(%d)->wait_for_go() not finishing\n",
  534. mgr->id);
  535. r = 0;
  536. break;
  537. }
  538. r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
  539. if (r == -ERESTARTSYS)
  540. break;
  541. if (r) {
  542. DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
  543. break;
  544. }
  545. }
  546. return r;
  547. }
  548. int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
  549. {
  550. unsigned long timeout = msecs_to_jiffies(500);
  551. struct overlay_cache_data *oc;
  552. struct omap_dss_device *dssdev;
  553. u32 irq;
  554. int r;
  555. int i;
  556. if (!ovl->manager)
  557. return 0;
  558. dssdev = ovl->manager->device;
  559. if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  560. return 0;
  561. if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE)
  562. return 0;
  563. if (dssdev->type == OMAP_DISPLAY_TYPE_VENC
  564. || dssdev->type == OMAP_DISPLAY_TYPE_HDMI) {
  565. irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
  566. } else {
  567. irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
  568. DISPC_IRQ_VSYNC : DISPC_IRQ_VSYNC2;
  569. }
  570. oc = &dss_cache.overlay_cache[ovl->id];
  571. i = 0;
  572. while (1) {
  573. unsigned long flags;
  574. bool shadow_dirty, dirty;
  575. spin_lock_irqsave(&dss_cache.lock, flags);
  576. dirty = oc->dirty;
  577. shadow_dirty = oc->shadow_dirty;
  578. spin_unlock_irqrestore(&dss_cache.lock, flags);
  579. if (!dirty && !shadow_dirty) {
  580. r = 0;
  581. break;
  582. }
  583. /* 4 iterations is the worst case:
  584. * 1 - initial iteration, dirty = true (between VFP and VSYNC)
  585. * 2 - first VSYNC, dirty = true
  586. * 3 - dirty = false, shadow_dirty = true
  587. * 4 - shadow_dirty = false */
  588. if (i++ == 3) {
  589. DSSERR("ovl(%d)->wait_for_go() not finishing\n",
  590. ovl->id);
  591. r = 0;
  592. break;
  593. }
  594. r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
  595. if (r == -ERESTARTSYS)
  596. break;
  597. if (r) {
  598. DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
  599. break;
  600. }
  601. }
  602. return r;
  603. }
  604. static int overlay_enabled(struct omap_overlay *ovl)
  605. {
  606. return ovl->info.enabled && ovl->manager && ovl->manager->device;
  607. }
  608. /* Is rect1 a subset of rect2? */
  609. static bool rectangle_subset(int x1, int y1, int w1, int h1,
  610. int x2, int y2, int w2, int h2)
  611. {
  612. if (x1 < x2 || y1 < y2)
  613. return false;
  614. if (x1 + w1 > x2 + w2)
  615. return false;
  616. if (y1 + h1 > y2 + h2)
  617. return false;
  618. return true;
  619. }
  620. /* Do rect1 and rect2 overlap? */
  621. static bool rectangle_intersects(int x1, int y1, int w1, int h1,
  622. int x2, int y2, int w2, int h2)
  623. {
  624. if (x1 >= x2 + w2)
  625. return false;
  626. if (x2 >= x1 + w1)
  627. return false;
  628. if (y1 >= y2 + h2)
  629. return false;
  630. if (y2 >= y1 + h1)
  631. return false;
  632. return true;
  633. }
  634. static bool dispc_is_overlay_scaled(struct overlay_cache_data *oc)
  635. {
  636. struct omap_overlay_info *oi = &oc->info;
  637. if (oi->out_width != 0 && oi->width != oi->out_width)
  638. return true;
  639. if (oi->out_height != 0 && oi->height != oi->out_height)
  640. return true;
  641. return false;
  642. }
  643. static int configure_overlay(enum omap_plane plane)
  644. {
  645. struct overlay_cache_data *c;
  646. struct manager_cache_data *mc;
  647. struct omap_overlay_info *oi, new_oi;
  648. struct omap_overlay_manager_info *mi;
  649. u16 outw, outh;
  650. u16 x, y, w, h;
  651. u32 paddr;
  652. int r;
  653. u16 orig_w, orig_h, orig_outw, orig_outh;
  654. DSSDBGF("%d", plane);
  655. c = &dss_cache.overlay_cache[plane];
  656. oi = &c->info;
  657. if (!c->enabled) {
  658. dispc_ovl_enable(plane, 0);
  659. return 0;
  660. }
  661. mc = &dss_cache.manager_cache[c->channel];
  662. mi = &mc->info;
  663. x = oi->pos_x;
  664. y = oi->pos_y;
  665. w = oi->width;
  666. h = oi->height;
  667. outw = oi->out_width == 0 ? oi->width : oi->out_width;
  668. outh = oi->out_height == 0 ? oi->height : oi->out_height;
  669. paddr = oi->paddr;
  670. orig_w = w;
  671. orig_h = h;
  672. orig_outw = outw;
  673. orig_outh = outh;
  674. if (mc->manual_update && mc->do_manual_update) {
  675. unsigned bpp;
  676. unsigned scale_x_m = w, scale_x_d = outw;
  677. unsigned scale_y_m = h, scale_y_d = outh;
  678. /* If the overlay is outside the update region, disable it */
  679. if (!rectangle_intersects(mc->x, mc->y, mc->w, mc->h,
  680. x, y, outw, outh)) {
  681. dispc_ovl_enable(plane, 0);
  682. return 0;
  683. }
  684. switch (oi->color_mode) {
  685. case OMAP_DSS_COLOR_NV12:
  686. bpp = 8;
  687. break;
  688. case OMAP_DSS_COLOR_RGB16:
  689. case OMAP_DSS_COLOR_ARGB16:
  690. case OMAP_DSS_COLOR_YUV2:
  691. case OMAP_DSS_COLOR_UYVY:
  692. case OMAP_DSS_COLOR_RGBA16:
  693. case OMAP_DSS_COLOR_RGBX16:
  694. case OMAP_DSS_COLOR_ARGB16_1555:
  695. case OMAP_DSS_COLOR_XRGB16_1555:
  696. bpp = 16;
  697. break;
  698. case OMAP_DSS_COLOR_RGB24P:
  699. bpp = 24;
  700. break;
  701. case OMAP_DSS_COLOR_RGB24U:
  702. case OMAP_DSS_COLOR_ARGB32:
  703. case OMAP_DSS_COLOR_RGBA32:
  704. case OMAP_DSS_COLOR_RGBX32:
  705. bpp = 32;
  706. break;
  707. default:
  708. BUG();
  709. }
  710. if (mc->x > oi->pos_x) {
  711. x = 0;
  712. outw -= (mc->x - oi->pos_x);
  713. paddr += (mc->x - oi->pos_x) *
  714. scale_x_m / scale_x_d * bpp / 8;
  715. } else {
  716. x = oi->pos_x - mc->x;
  717. }
  718. if (mc->y > oi->pos_y) {
  719. y = 0;
  720. outh -= (mc->y - oi->pos_y);
  721. paddr += (mc->y - oi->pos_y) *
  722. scale_y_m / scale_y_d *
  723. oi->screen_width * bpp / 8;
  724. } else {
  725. y = oi->pos_y - mc->y;
  726. }
  727. if (mc->w < (x + outw))
  728. outw -= (x + outw) - (mc->w);
  729. if (mc->h < (y + outh))
  730. outh -= (y + outh) - (mc->h);
  731. w = w * outw / orig_outw;
  732. h = h * outh / orig_outh;
  733. /* YUV mode overlay's input width has to be even and the
  734. * algorithm above may adjust the width to be odd.
  735. *
  736. * Here we adjust the width if needed, preferring to increase
  737. * the width if the original width was bigger.
  738. */
  739. if ((w & 1) &&
  740. (oi->color_mode == OMAP_DSS_COLOR_YUV2 ||
  741. oi->color_mode == OMAP_DSS_COLOR_UYVY)) {
  742. if (orig_w > w)
  743. w += 1;
  744. else
  745. w -= 1;
  746. }
  747. }
  748. new_oi = *oi;
  749. /* update new_oi members which could have been possibly updated */
  750. new_oi.pos_x = x;
  751. new_oi.pos_y = y;
  752. new_oi.width = w;
  753. new_oi.height = h;
  754. new_oi.out_width = outw;
  755. new_oi.out_height = outh;
  756. new_oi.paddr = paddr;
  757. r = dispc_ovl_setup(plane, &new_oi, c->ilace, c->channel,
  758. c->replication, c->fifo_low, c->fifo_high);
  759. if (r) {
  760. /* this shouldn't happen */
  761. DSSERR("dispc_ovl_setup failed for ovl %d\n", plane);
  762. dispc_ovl_enable(plane, 0);
  763. return r;
  764. }
  765. dispc_ovl_enable(plane, 1);
  766. return 0;
  767. }
  768. static void configure_manager(enum omap_channel channel)
  769. {
  770. struct omap_overlay_manager_info *mi;
  771. DSSDBGF("%d", channel);
  772. /* picking info from the cache */
  773. mi = &dss_cache.manager_cache[channel].info;
  774. dispc_mgr_set_default_color(channel, mi->default_color);
  775. dispc_mgr_set_trans_key(channel, mi->trans_key_type, mi->trans_key);
  776. dispc_mgr_enable_trans_key(channel, mi->trans_enabled);
  777. dispc_mgr_enable_alpha_fixed_zorder(channel, mi->partial_alpha_enabled);
  778. if (dss_has_feature(FEAT_CPR)) {
  779. dispc_mgr_enable_cpr(channel, mi->cpr_enable);
  780. dispc_mgr_set_cpr_coef(channel, &mi->cpr_coefs);
  781. }
  782. }
  783. /* configure_dispc() tries to write values from cache to shadow registers.
  784. * It writes only to those managers/overlays that are not busy.
  785. * returns 0 if everything could be written to shadow registers.
  786. * returns 1 if not everything could be written to shadow registers. */
  787. static int configure_dispc(void)
  788. {
  789. struct overlay_cache_data *oc;
  790. struct manager_cache_data *mc;
  791. const int num_ovls = dss_feat_get_num_ovls();
  792. const int num_mgrs = dss_feat_get_num_mgrs();
  793. int i;
  794. int r;
  795. bool mgr_busy[MAX_DSS_MANAGERS];
  796. bool mgr_go[MAX_DSS_MANAGERS];
  797. bool busy;
  798. r = 0;
  799. busy = false;
  800. for (i = 0; i < num_mgrs; i++) {
  801. mgr_busy[i] = dispc_mgr_go_busy(i);
  802. mgr_go[i] = false;
  803. }
  804. /* Commit overlay settings */
  805. for (i = 0; i < num_ovls; ++i) {
  806. oc = &dss_cache.overlay_cache[i];
  807. mc = &dss_cache.manager_cache[oc->channel];
  808. if (!oc->dirty)
  809. continue;
  810. if (mc->manual_update && !mc->do_manual_update)
  811. continue;
  812. if (mgr_busy[oc->channel]) {
  813. busy = true;
  814. continue;
  815. }
  816. r = configure_overlay(i);
  817. if (r)
  818. DSSERR("configure_overlay %d failed\n", i);
  819. oc->dirty = false;
  820. oc->shadow_dirty = true;
  821. mgr_go[oc->channel] = true;
  822. }
  823. /* Commit manager settings */
  824. for (i = 0; i < num_mgrs; ++i) {
  825. mc = &dss_cache.manager_cache[i];
  826. if (!mc->dirty)
  827. continue;
  828. if (mc->manual_update && !mc->do_manual_update)
  829. continue;
  830. if (mgr_busy[i]) {
  831. busy = true;
  832. continue;
  833. }
  834. configure_manager(i);
  835. mc->dirty = false;
  836. mc->shadow_dirty = true;
  837. mgr_go[i] = true;
  838. }
  839. /* set GO */
  840. for (i = 0; i < num_mgrs; ++i) {
  841. mc = &dss_cache.manager_cache[i];
  842. if (!mgr_go[i])
  843. continue;
  844. /* We don't need GO with manual update display. LCD iface will
  845. * always be turned off after frame, and new settings will be
  846. * taken in to use at next update */
  847. if (!mc->manual_update)
  848. dispc_mgr_go(i);
  849. }
  850. if (busy)
  851. r = 1;
  852. else
  853. r = 0;
  854. return r;
  855. }
  856. /* Make the coordinates even. There are some strange problems with OMAP and
  857. * partial DSI update when the update widths are odd. */
  858. static void make_even(u16 *x, u16 *w)
  859. {
  860. u16 x1, x2;
  861. x1 = *x;
  862. x2 = *x + *w;
  863. x1 &= ~1;
  864. x2 = ALIGN(x2, 2);
  865. *x = x1;
  866. *w = x2 - x1;
  867. }
  868. /* Configure dispc for partial update. Return possibly modified update
  869. * area */
  870. void dss_setup_partial_planes(struct omap_dss_device *dssdev,
  871. u16 *xi, u16 *yi, u16 *wi, u16 *hi, bool enlarge_update_area)
  872. {
  873. struct overlay_cache_data *oc;
  874. struct manager_cache_data *mc;
  875. struct omap_overlay_info *oi;
  876. const int num_ovls = dss_feat_get_num_ovls();
  877. struct omap_overlay_manager *mgr;
  878. int i;
  879. u16 x, y, w, h;
  880. unsigned long flags;
  881. bool area_changed;
  882. x = *xi;
  883. y = *yi;
  884. w = *wi;
  885. h = *hi;
  886. DSSDBG("dispc_setup_partial_planes %d,%d %dx%d\n",
  887. *xi, *yi, *wi, *hi);
  888. mgr = dssdev->manager;
  889. if (!mgr) {
  890. DSSDBG("no manager\n");
  891. return;
  892. }
  893. make_even(&x, &w);
  894. spin_lock_irqsave(&dss_cache.lock, flags);
  895. /*
  896. * Execute the outer loop until the inner loop has completed
  897. * once without increasing the update area. This will ensure that
  898. * all scaled overlays end up completely within the update area.
  899. */
  900. do {
  901. area_changed = false;
  902. /* We need to show the whole overlay if it is scaled. So look
  903. * for those, and make the update area larger if found.
  904. * Also mark the overlay cache dirty */
  905. for (i = 0; i < num_ovls; ++i) {
  906. unsigned x1, y1, x2, y2;
  907. unsigned outw, outh;
  908. oc = &dss_cache.overlay_cache[i];
  909. oi = &oc->info;
  910. if (oc->channel != mgr->id)
  911. continue;
  912. oc->dirty = true;
  913. if (!enlarge_update_area)
  914. continue;
  915. if (!oc->enabled)
  916. continue;
  917. if (!dispc_is_overlay_scaled(oc))
  918. continue;
  919. outw = oi->out_width == 0 ?
  920. oi->width : oi->out_width;
  921. outh = oi->out_height == 0 ?
  922. oi->height : oi->out_height;
  923. /* is the overlay outside the update region? */
  924. if (!rectangle_intersects(x, y, w, h,
  925. oi->pos_x, oi->pos_y,
  926. outw, outh))
  927. continue;
  928. /* if the overlay totally inside the update region? */
  929. if (rectangle_subset(oi->pos_x, oi->pos_y, outw, outh,
  930. x, y, w, h))
  931. continue;
  932. if (x > oi->pos_x)
  933. x1 = oi->pos_x;
  934. else
  935. x1 = x;
  936. if (y > oi->pos_y)
  937. y1 = oi->pos_y;
  938. else
  939. y1 = y;
  940. if ((x + w) < (oi->pos_x + outw))
  941. x2 = oi->pos_x + outw;
  942. else
  943. x2 = x + w;
  944. if ((y + h) < (oi->pos_y + outh))
  945. y2 = oi->pos_y + outh;
  946. else
  947. y2 = y + h;
  948. x = x1;
  949. y = y1;
  950. w = x2 - x1;
  951. h = y2 - y1;
  952. make_even(&x, &w);
  953. DSSDBG("changing upd area due to ovl(%d) "
  954. "scaling %d,%d %dx%d\n",
  955. i, x, y, w, h);
  956. area_changed = true;
  957. }
  958. } while (area_changed);
  959. mc = &dss_cache.manager_cache[mgr->id];
  960. mc->do_manual_update = true;
  961. mc->enlarge_update_area = enlarge_update_area;
  962. mc->x = x;
  963. mc->y = y;
  964. mc->w = w;
  965. mc->h = h;
  966. configure_dispc();
  967. mc->do_manual_update = false;
  968. spin_unlock_irqrestore(&dss_cache.lock, flags);
  969. *xi = x;
  970. *yi = y;
  971. *wi = w;
  972. *hi = h;
  973. }
  974. void dss_start_update(struct omap_dss_device *dssdev)
  975. {
  976. struct manager_cache_data *mc;
  977. struct overlay_cache_data *oc;
  978. const int num_ovls = dss_feat_get_num_ovls();
  979. const int num_mgrs = dss_feat_get_num_mgrs();
  980. struct omap_overlay_manager *mgr;
  981. int i;
  982. mgr = dssdev->manager;
  983. for (i = 0; i < num_ovls; ++i) {
  984. oc = &dss_cache.overlay_cache[i];
  985. if (oc->channel != mgr->id)
  986. continue;
  987. oc->shadow_dirty = false;
  988. }
  989. for (i = 0; i < num_mgrs; ++i) {
  990. mc = &dss_cache.manager_cache[i];
  991. if (mgr->id != i)
  992. continue;
  993. mc->shadow_dirty = false;
  994. }
  995. dssdev->manager->enable(dssdev->manager);
  996. }
  997. static void dss_apply_irq_handler(void *data, u32 mask)
  998. {
  999. struct manager_cache_data *mc;
  1000. struct overlay_cache_data *oc;
  1001. const int num_ovls = dss_feat_get_num_ovls();
  1002. const int num_mgrs = dss_feat_get_num_mgrs();
  1003. int i, r;
  1004. bool mgr_busy[MAX_DSS_MANAGERS];
  1005. u32 irq_mask;
  1006. for (i = 0; i < num_mgrs; i++)
  1007. mgr_busy[i] = dispc_mgr_go_busy(i);
  1008. spin_lock(&dss_cache.lock);
  1009. for (i = 0; i < num_ovls; ++i) {
  1010. oc = &dss_cache.overlay_cache[i];
  1011. if (!mgr_busy[oc->channel])
  1012. oc->shadow_dirty = false;
  1013. }
  1014. for (i = 0; i < num_mgrs; ++i) {
  1015. mc = &dss_cache.manager_cache[i];
  1016. if (!mgr_busy[i])
  1017. mc->shadow_dirty = false;
  1018. }
  1019. r = configure_dispc();
  1020. if (r == 1)
  1021. goto end;
  1022. /* re-read busy flags */
  1023. for (i = 0; i < num_mgrs; i++)
  1024. mgr_busy[i] = dispc_mgr_go_busy(i);
  1025. /* keep running as long as there are busy managers, so that
  1026. * we can collect overlay-applied information */
  1027. for (i = 0; i < num_mgrs; ++i) {
  1028. if (mgr_busy[i])
  1029. goto end;
  1030. }
  1031. irq_mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
  1032. DISPC_IRQ_EVSYNC_EVEN;
  1033. if (dss_has_feature(FEAT_MGR_LCD2))
  1034. irq_mask |= DISPC_IRQ_VSYNC2;
  1035. omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, irq_mask);
  1036. dss_cache.irq_enabled = false;
  1037. end:
  1038. spin_unlock(&dss_cache.lock);
  1039. }
  1040. static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
  1041. {
  1042. struct overlay_cache_data *oc;
  1043. struct manager_cache_data *mc;
  1044. int i;
  1045. struct omap_overlay *ovl;
  1046. int num_planes_enabled = 0;
  1047. bool use_fifomerge;
  1048. unsigned long flags;
  1049. int r;
  1050. DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
  1051. r = dispc_runtime_get();
  1052. if (r)
  1053. return r;
  1054. spin_lock_irqsave(&dss_cache.lock, flags);
  1055. /* Configure overlays */
  1056. for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
  1057. struct omap_dss_device *dssdev;
  1058. ovl = omap_dss_get_overlay(i);
  1059. oc = &dss_cache.overlay_cache[ovl->id];
  1060. if (ovl->manager_changed) {
  1061. ovl->manager_changed = false;
  1062. ovl->info_dirty = true;
  1063. }
  1064. if (!overlay_enabled(ovl)) {
  1065. if (oc->enabled) {
  1066. oc->enabled = false;
  1067. oc->dirty = true;
  1068. }
  1069. continue;
  1070. }
  1071. if (!ovl->info_dirty) {
  1072. if (oc->enabled)
  1073. ++num_planes_enabled;
  1074. continue;
  1075. }
  1076. dssdev = ovl->manager->device;
  1077. if (dss_check_overlay(ovl, dssdev)) {
  1078. if (oc->enabled) {
  1079. oc->enabled = false;
  1080. oc->dirty = true;
  1081. }
  1082. continue;
  1083. }
  1084. ovl->info_dirty = false;
  1085. oc->dirty = true;
  1086. oc->info = ovl->info;
  1087. oc->replication =
  1088. dss_use_replication(dssdev, ovl->info.color_mode);
  1089. oc->ilace = dssdev->type == OMAP_DISPLAY_TYPE_VENC;
  1090. oc->channel = ovl->manager->id;
  1091. oc->enabled = true;
  1092. ++num_planes_enabled;
  1093. }
  1094. /* Configure managers */
  1095. list_for_each_entry(mgr, &manager_list, list) {
  1096. struct omap_dss_device *dssdev;
  1097. mc = &dss_cache.manager_cache[mgr->id];
  1098. if (mgr->device_changed) {
  1099. mgr->device_changed = false;
  1100. mgr->info_dirty = true;
  1101. }
  1102. if (!mgr->info_dirty)
  1103. continue;
  1104. if (!mgr->device)
  1105. continue;
  1106. dssdev = mgr->device;
  1107. mgr->info_dirty = false;
  1108. mc->dirty = true;
  1109. mc->info = mgr->info;
  1110. mc->manual_update =
  1111. dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
  1112. }
  1113. /* XXX TODO: Try to get fifomerge working. The problem is that it
  1114. * affects both managers, not individually but at the same time. This
  1115. * means the change has to be well synchronized. I guess the proper way
  1116. * is to have a two step process for fifo merge:
  1117. * fifomerge enable:
  1118. * 1. disable other planes, leaving one plane enabled
  1119. * 2. wait until the planes are disabled on HW
  1120. * 3. config merged fifo thresholds, enable fifomerge
  1121. * fifomerge disable:
  1122. * 1. config unmerged fifo thresholds, disable fifomerge
  1123. * 2. wait until fifo changes are in HW
  1124. * 3. enable planes
  1125. */
  1126. use_fifomerge = false;
  1127. /* Configure overlay fifos */
  1128. for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
  1129. struct omap_dss_device *dssdev;
  1130. u32 size, burst_size;
  1131. ovl = omap_dss_get_overlay(i);
  1132. oc = &dss_cache.overlay_cache[ovl->id];
  1133. if (!oc->enabled)
  1134. continue;
  1135. dssdev = ovl->manager->device;
  1136. size = dispc_ovl_get_fifo_size(ovl->id);
  1137. if (use_fifomerge)
  1138. size *= 3;
  1139. burst_size = dispc_ovl_get_burst_size(ovl->id);
  1140. switch (dssdev->type) {
  1141. case OMAP_DISPLAY_TYPE_DPI:
  1142. case OMAP_DISPLAY_TYPE_DBI:
  1143. case OMAP_DISPLAY_TYPE_SDI:
  1144. case OMAP_DISPLAY_TYPE_VENC:
  1145. case OMAP_DISPLAY_TYPE_HDMI:
  1146. default_get_overlay_fifo_thresholds(ovl->id, size,
  1147. burst_size, &oc->fifo_low,
  1148. &oc->fifo_high);
  1149. break;
  1150. #ifdef CONFIG_OMAP2_DSS_DSI
  1151. case OMAP_DISPLAY_TYPE_DSI:
  1152. dsi_get_overlay_fifo_thresholds(ovl->id, size,
  1153. burst_size, &oc->fifo_low,
  1154. &oc->fifo_high);
  1155. break;
  1156. #endif
  1157. default:
  1158. BUG();
  1159. }
  1160. }
  1161. r = 0;
  1162. if (!dss_cache.irq_enabled) {
  1163. u32 mask;
  1164. mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
  1165. DISPC_IRQ_EVSYNC_EVEN;
  1166. if (dss_has_feature(FEAT_MGR_LCD2))
  1167. mask |= DISPC_IRQ_VSYNC2;
  1168. r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
  1169. dss_cache.irq_enabled = true;
  1170. }
  1171. configure_dispc();
  1172. spin_unlock_irqrestore(&dss_cache.lock, flags);
  1173. dispc_runtime_put();
  1174. return r;
  1175. }
  1176. static int dss_check_manager(struct omap_overlay_manager *mgr)
  1177. {
  1178. if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
  1179. /*
  1180. * OMAP3 supports only graphics source transparency color key
  1181. * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
  1182. * Alpha Mode
  1183. */
  1184. if (mgr->info.partial_alpha_enabled && mgr->info.trans_enabled
  1185. && mgr->info.trans_key_type !=
  1186. OMAP_DSS_COLOR_KEY_GFX_DST)
  1187. return -EINVAL;
  1188. }
  1189. return 0;
  1190. }
  1191. static int omap_dss_mgr_set_info(struct omap_overlay_manager *mgr,
  1192. struct omap_overlay_manager_info *info)
  1193. {
  1194. int r;
  1195. struct omap_overlay_manager_info old_info;
  1196. old_info = mgr->info;
  1197. mgr->info = *info;
  1198. r = dss_check_manager(mgr);
  1199. if (r) {
  1200. mgr->info = old_info;
  1201. return r;
  1202. }
  1203. mgr->info_dirty = true;
  1204. return 0;
  1205. }
  1206. static void omap_dss_mgr_get_info(struct omap_overlay_manager *mgr,
  1207. struct omap_overlay_manager_info *info)
  1208. {
  1209. *info = mgr->info;
  1210. }
  1211. static int dss_mgr_enable(struct omap_overlay_manager *mgr)
  1212. {
  1213. dispc_mgr_enable(mgr->id, 1);
  1214. return 0;
  1215. }
  1216. static int dss_mgr_disable(struct omap_overlay_manager *mgr)
  1217. {
  1218. dispc_mgr_enable(mgr->id, 0);
  1219. return 0;
  1220. }
  1221. static void omap_dss_add_overlay_manager(struct omap_overlay_manager *manager)
  1222. {
  1223. ++num_managers;
  1224. list_add_tail(&manager->list, &manager_list);
  1225. }
  1226. int dss_init_overlay_managers(struct platform_device *pdev)
  1227. {
  1228. int i, r;
  1229. spin_lock_init(&dss_cache.lock);
  1230. INIT_LIST_HEAD(&manager_list);
  1231. num_managers = 0;
  1232. for (i = 0; i < dss_feat_get_num_mgrs(); ++i) {
  1233. struct omap_overlay_manager *mgr;
  1234. mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
  1235. BUG_ON(mgr == NULL);
  1236. switch (i) {
  1237. case 0:
  1238. mgr->name = "lcd";
  1239. mgr->id = OMAP_DSS_CHANNEL_LCD;
  1240. break;
  1241. case 1:
  1242. mgr->name = "tv";
  1243. mgr->id = OMAP_DSS_CHANNEL_DIGIT;
  1244. break;
  1245. case 2:
  1246. mgr->name = "lcd2";
  1247. mgr->id = OMAP_DSS_CHANNEL_LCD2;
  1248. break;
  1249. }
  1250. mgr->set_device = &omap_dss_set_device;
  1251. mgr->unset_device = &omap_dss_unset_device;
  1252. mgr->apply = &omap_dss_mgr_apply;
  1253. mgr->set_manager_info = &omap_dss_mgr_set_info;
  1254. mgr->get_manager_info = &omap_dss_mgr_get_info;
  1255. mgr->wait_for_go = &dss_mgr_wait_for_go;
  1256. mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
  1257. mgr->enable = &dss_mgr_enable;
  1258. mgr->disable = &dss_mgr_disable;
  1259. mgr->caps = 0;
  1260. mgr->supported_displays =
  1261. dss_feat_get_supported_displays(mgr->id);
  1262. dss_overlay_setup_dispc_manager(mgr);
  1263. omap_dss_add_overlay_manager(mgr);
  1264. r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
  1265. &pdev->dev.kobj, "manager%d", i);
  1266. if (r) {
  1267. DSSERR("failed to create sysfs file\n");
  1268. continue;
  1269. }
  1270. }
  1271. return 0;
  1272. }
  1273. void dss_uninit_overlay_managers(struct platform_device *pdev)
  1274. {
  1275. struct omap_overlay_manager *mgr;
  1276. while (!list_empty(&manager_list)) {
  1277. mgr = list_first_entry(&manager_list,
  1278. struct omap_overlay_manager, list);
  1279. list_del(&mgr->list);
  1280. kobject_del(&mgr->kobj);
  1281. kobject_put(&mgr->kobj);
  1282. kfree(mgr);
  1283. }
  1284. num_managers = 0;
  1285. }
  1286. int omap_dss_get_num_overlay_managers(void)
  1287. {
  1288. return num_managers;
  1289. }
  1290. EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
  1291. struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
  1292. {
  1293. int i = 0;
  1294. struct omap_overlay_manager *mgr;
  1295. list_for_each_entry(mgr, &manager_list, list) {
  1296. if (i++ == num)
  1297. return mgr;
  1298. }
  1299. return NULL;
  1300. }
  1301. EXPORT_SYMBOL(omap_dss_get_overlay_manager);