manager.c 35 KB

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