manager.c 34 KB

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