manager.c 35 KB

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