manager.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  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. }
  652. r = dispc_setup_plane(plane,
  653. paddr,
  654. c->screen_width,
  655. x, y,
  656. w, h,
  657. outw, outh,
  658. c->color_mode,
  659. c->ilace,
  660. c->rotation_type,
  661. c->rotation,
  662. c->mirror,
  663. c->global_alpha);
  664. if (r) {
  665. /* this shouldn't happen */
  666. DSSERR("dispc_setup_plane failed for ovl %d\n", plane);
  667. dispc_enable_plane(plane, 0);
  668. return r;
  669. }
  670. dispc_enable_replication(plane, c->replication);
  671. dispc_set_burst_size(plane, c->burst_size);
  672. dispc_setup_plane_fifo(plane, c->fifo_low, c->fifo_high);
  673. dispc_enable_plane(plane, 1);
  674. return 0;
  675. }
  676. static void configure_manager(enum omap_channel channel)
  677. {
  678. struct manager_cache_data *c;
  679. DSSDBGF("%d", channel);
  680. c = &dss_cache.manager_cache[channel];
  681. dispc_set_default_color(channel, c->default_color);
  682. dispc_set_trans_key(channel, c->trans_key_type, c->trans_key);
  683. dispc_enable_trans_key(channel, c->trans_enabled);
  684. dispc_enable_alpha_blending(channel, c->alpha_enabled);
  685. }
  686. /* configure_dispc() tries to write values from cache to shadow registers.
  687. * It writes only to those managers/overlays that are not busy.
  688. * returns 0 if everything could be written to shadow registers.
  689. * returns 1 if not everything could be written to shadow registers. */
  690. static int configure_dispc(void)
  691. {
  692. struct overlay_cache_data *oc;
  693. struct manager_cache_data *mc;
  694. const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
  695. const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
  696. int i;
  697. int r;
  698. bool mgr_busy[2];
  699. bool mgr_go[2];
  700. bool busy;
  701. r = 0;
  702. busy = false;
  703. mgr_busy[0] = dispc_go_busy(0);
  704. mgr_busy[1] = dispc_go_busy(1);
  705. mgr_go[0] = false;
  706. mgr_go[1] = false;
  707. /* Commit overlay settings */
  708. for (i = 0; i < num_ovls; ++i) {
  709. oc = &dss_cache.overlay_cache[i];
  710. mc = &dss_cache.manager_cache[oc->channel];
  711. if (!oc->dirty)
  712. continue;
  713. if (oc->manual_update && !mc->do_manual_update)
  714. continue;
  715. if (mgr_busy[oc->channel]) {
  716. busy = true;
  717. continue;
  718. }
  719. r = configure_overlay(i);
  720. if (r)
  721. DSSERR("configure_overlay %d failed\n", i);
  722. oc->dirty = false;
  723. oc->shadow_dirty = true;
  724. mgr_go[oc->channel] = true;
  725. }
  726. /* Commit manager settings */
  727. for (i = 0; i < num_mgrs; ++i) {
  728. mc = &dss_cache.manager_cache[i];
  729. if (!mc->dirty)
  730. continue;
  731. if (mc->manual_update && !mc->do_manual_update)
  732. continue;
  733. if (mgr_busy[i]) {
  734. busy = true;
  735. continue;
  736. }
  737. configure_manager(i);
  738. mc->dirty = false;
  739. mc->shadow_dirty = true;
  740. mgr_go[i] = true;
  741. }
  742. /* set GO */
  743. for (i = 0; i < num_mgrs; ++i) {
  744. mc = &dss_cache.manager_cache[i];
  745. if (!mgr_go[i])
  746. continue;
  747. /* We don't need GO with manual update display. LCD iface will
  748. * always be turned off after frame, and new settings will be
  749. * taken in to use at next update */
  750. if (!mc->manual_upd_display)
  751. dispc_go(i);
  752. }
  753. if (busy)
  754. r = 1;
  755. else
  756. r = 0;
  757. return r;
  758. }
  759. /* Make the coordinates even. There are some strange problems with OMAP and
  760. * partial DSI update when the update widths are odd. */
  761. static void make_even(u16 *x, u16 *w)
  762. {
  763. u16 x1, x2;
  764. x1 = *x;
  765. x2 = *x + *w;
  766. x1 &= ~1;
  767. x2 = ALIGN(x2, 2);
  768. *x = x1;
  769. *w = x2 - x1;
  770. }
  771. /* Configure dispc for partial update. Return possibly modified update
  772. * area */
  773. void dss_setup_partial_planes(struct omap_dss_device *dssdev,
  774. u16 *xi, u16 *yi, u16 *wi, u16 *hi, bool enlarge_update_area)
  775. {
  776. struct overlay_cache_data *oc;
  777. struct manager_cache_data *mc;
  778. const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
  779. struct omap_overlay_manager *mgr;
  780. int i;
  781. u16 x, y, w, h;
  782. unsigned long flags;
  783. bool area_changed;
  784. x = *xi;
  785. y = *yi;
  786. w = *wi;
  787. h = *hi;
  788. DSSDBG("dispc_setup_partial_planes %d,%d %dx%d\n",
  789. *xi, *yi, *wi, *hi);
  790. mgr = dssdev->manager;
  791. if (!mgr) {
  792. DSSDBG("no manager\n");
  793. return;
  794. }
  795. make_even(&x, &w);
  796. spin_lock_irqsave(&dss_cache.lock, flags);
  797. /*
  798. * Execute the outer loop until the inner loop has completed
  799. * once without increasing the update area. This will ensure that
  800. * all scaled overlays end up completely within the update area.
  801. */
  802. do {
  803. area_changed = false;
  804. /* We need to show the whole overlay if it is scaled. So look
  805. * for those, and make the update area larger if found.
  806. * Also mark the overlay cache dirty */
  807. for (i = 0; i < num_ovls; ++i) {
  808. unsigned x1, y1, x2, y2;
  809. unsigned outw, outh;
  810. oc = &dss_cache.overlay_cache[i];
  811. if (oc->channel != mgr->id)
  812. continue;
  813. oc->dirty = true;
  814. if (!enlarge_update_area)
  815. continue;
  816. if (!oc->enabled)
  817. continue;
  818. if (!dispc_is_overlay_scaled(oc))
  819. continue;
  820. outw = oc->out_width == 0 ?
  821. oc->width : oc->out_width;
  822. outh = oc->out_height == 0 ?
  823. oc->height : oc->out_height;
  824. /* is the overlay outside the update region? */
  825. if (!rectangle_intersects(x, y, w, h,
  826. oc->pos_x, oc->pos_y,
  827. outw, outh))
  828. continue;
  829. /* if the overlay totally inside the update region? */
  830. if (rectangle_subset(oc->pos_x, oc->pos_y, outw, outh,
  831. x, y, w, h))
  832. continue;
  833. if (x > oc->pos_x)
  834. x1 = oc->pos_x;
  835. else
  836. x1 = x;
  837. if (y > oc->pos_y)
  838. y1 = oc->pos_y;
  839. else
  840. y1 = y;
  841. if ((x + w) < (oc->pos_x + outw))
  842. x2 = oc->pos_x + outw;
  843. else
  844. x2 = x + w;
  845. if ((y + h) < (oc->pos_y + outh))
  846. y2 = oc->pos_y + outh;
  847. else
  848. y2 = y + h;
  849. x = x1;
  850. y = y1;
  851. w = x2 - x1;
  852. h = y2 - y1;
  853. make_even(&x, &w);
  854. DSSDBG("changing upd area due to ovl(%d) "
  855. "scaling %d,%d %dx%d\n",
  856. i, x, y, w, h);
  857. area_changed = true;
  858. }
  859. } while (area_changed);
  860. mc = &dss_cache.manager_cache[mgr->id];
  861. mc->do_manual_update = true;
  862. mc->enlarge_update_area = enlarge_update_area;
  863. mc->x = x;
  864. mc->y = y;
  865. mc->w = w;
  866. mc->h = h;
  867. configure_dispc();
  868. mc->do_manual_update = false;
  869. spin_unlock_irqrestore(&dss_cache.lock, flags);
  870. *xi = x;
  871. *yi = y;
  872. *wi = w;
  873. *hi = h;
  874. }
  875. void dss_start_update(struct omap_dss_device *dssdev)
  876. {
  877. struct manager_cache_data *mc;
  878. struct overlay_cache_data *oc;
  879. const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
  880. const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
  881. struct omap_overlay_manager *mgr;
  882. int i;
  883. mgr = dssdev->manager;
  884. for (i = 0; i < num_ovls; ++i) {
  885. oc = &dss_cache.overlay_cache[i];
  886. if (oc->channel != mgr->id)
  887. continue;
  888. oc->shadow_dirty = false;
  889. }
  890. for (i = 0; i < num_mgrs; ++i) {
  891. mc = &dss_cache.manager_cache[i];
  892. if (mgr->id != i)
  893. continue;
  894. mc->shadow_dirty = false;
  895. }
  896. dssdev->manager->enable(dssdev->manager);
  897. }
  898. static void dss_apply_irq_handler(void *data, u32 mask)
  899. {
  900. struct manager_cache_data *mc;
  901. struct overlay_cache_data *oc;
  902. const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
  903. const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
  904. int i, r;
  905. bool mgr_busy[2];
  906. mgr_busy[0] = dispc_go_busy(0);
  907. mgr_busy[1] = dispc_go_busy(1);
  908. spin_lock(&dss_cache.lock);
  909. for (i = 0; i < num_ovls; ++i) {
  910. oc = &dss_cache.overlay_cache[i];
  911. if (!mgr_busy[oc->channel])
  912. oc->shadow_dirty = false;
  913. }
  914. for (i = 0; i < num_mgrs; ++i) {
  915. mc = &dss_cache.manager_cache[i];
  916. if (!mgr_busy[i])
  917. mc->shadow_dirty = false;
  918. }
  919. r = configure_dispc();
  920. if (r == 1)
  921. goto end;
  922. /* re-read busy flags */
  923. mgr_busy[0] = dispc_go_busy(0);
  924. mgr_busy[1] = dispc_go_busy(1);
  925. /* keep running as long as there are busy managers, so that
  926. * we can collect overlay-applied information */
  927. for (i = 0; i < num_mgrs; ++i) {
  928. if (mgr_busy[i])
  929. goto end;
  930. }
  931. omap_dispc_unregister_isr(dss_apply_irq_handler, NULL,
  932. DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
  933. DISPC_IRQ_EVSYNC_EVEN);
  934. dss_cache.irq_enabled = false;
  935. end:
  936. spin_unlock(&dss_cache.lock);
  937. }
  938. static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
  939. {
  940. struct overlay_cache_data *oc;
  941. struct manager_cache_data *mc;
  942. int i;
  943. struct omap_overlay *ovl;
  944. int num_planes_enabled = 0;
  945. bool use_fifomerge;
  946. unsigned long flags;
  947. int r;
  948. DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
  949. spin_lock_irqsave(&dss_cache.lock, flags);
  950. /* Configure overlays */
  951. for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
  952. struct omap_dss_device *dssdev;
  953. ovl = omap_dss_get_overlay(i);
  954. if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
  955. continue;
  956. oc = &dss_cache.overlay_cache[ovl->id];
  957. if (!overlay_enabled(ovl)) {
  958. if (oc->enabled) {
  959. oc->enabled = false;
  960. oc->dirty = true;
  961. }
  962. continue;
  963. }
  964. if (!ovl->info_dirty) {
  965. if (oc->enabled)
  966. ++num_planes_enabled;
  967. continue;
  968. }
  969. dssdev = ovl->manager->device;
  970. if (dss_check_overlay(ovl, dssdev)) {
  971. if (oc->enabled) {
  972. oc->enabled = false;
  973. oc->dirty = true;
  974. }
  975. continue;
  976. }
  977. ovl->info_dirty = false;
  978. oc->dirty = true;
  979. oc->paddr = ovl->info.paddr;
  980. oc->vaddr = ovl->info.vaddr;
  981. oc->screen_width = ovl->info.screen_width;
  982. oc->width = ovl->info.width;
  983. oc->height = ovl->info.height;
  984. oc->color_mode = ovl->info.color_mode;
  985. oc->rotation = ovl->info.rotation;
  986. oc->rotation_type = ovl->info.rotation_type;
  987. oc->mirror = ovl->info.mirror;
  988. oc->pos_x = ovl->info.pos_x;
  989. oc->pos_y = ovl->info.pos_y;
  990. oc->out_width = ovl->info.out_width;
  991. oc->out_height = ovl->info.out_height;
  992. oc->global_alpha = ovl->info.global_alpha;
  993. oc->replication =
  994. dss_use_replication(dssdev, ovl->info.color_mode);
  995. oc->ilace = dssdev->type == OMAP_DISPLAY_TYPE_VENC;
  996. oc->channel = ovl->manager->id;
  997. oc->enabled = true;
  998. oc->manual_update =
  999. dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE &&
  1000. dssdev->driver->get_update_mode(dssdev) !=
  1001. OMAP_DSS_UPDATE_AUTO;
  1002. ++num_planes_enabled;
  1003. }
  1004. /* Configure managers */
  1005. list_for_each_entry(mgr, &manager_list, list) {
  1006. struct omap_dss_device *dssdev;
  1007. if (!(mgr->caps & OMAP_DSS_OVL_MGR_CAP_DISPC))
  1008. continue;
  1009. mc = &dss_cache.manager_cache[mgr->id];
  1010. if (mgr->device_changed) {
  1011. mgr->device_changed = false;
  1012. mgr->info_dirty = true;
  1013. }
  1014. if (!mgr->info_dirty)
  1015. continue;
  1016. if (!mgr->device)
  1017. continue;
  1018. dssdev = mgr->device;
  1019. mgr->info_dirty = false;
  1020. mc->dirty = true;
  1021. mc->default_color = mgr->info.default_color;
  1022. mc->trans_key_type = mgr->info.trans_key_type;
  1023. mc->trans_key = mgr->info.trans_key;
  1024. mc->trans_enabled = mgr->info.trans_enabled;
  1025. mc->alpha_enabled = mgr->info.alpha_enabled;
  1026. mc->manual_upd_display =
  1027. dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
  1028. mc->manual_update =
  1029. dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE &&
  1030. dssdev->driver->get_update_mode(dssdev) !=
  1031. OMAP_DSS_UPDATE_AUTO;
  1032. }
  1033. /* XXX TODO: Try to get fifomerge working. The problem is that it
  1034. * affects both managers, not individually but at the same time. This
  1035. * means the change has to be well synchronized. I guess the proper way
  1036. * is to have a two step process for fifo merge:
  1037. * fifomerge enable:
  1038. * 1. disable other planes, leaving one plane enabled
  1039. * 2. wait until the planes are disabled on HW
  1040. * 3. config merged fifo thresholds, enable fifomerge
  1041. * fifomerge disable:
  1042. * 1. config unmerged fifo thresholds, disable fifomerge
  1043. * 2. wait until fifo changes are in HW
  1044. * 3. enable planes
  1045. */
  1046. use_fifomerge = false;
  1047. /* Configure overlay fifos */
  1048. for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
  1049. struct omap_dss_device *dssdev;
  1050. u32 size;
  1051. ovl = omap_dss_get_overlay(i);
  1052. if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
  1053. continue;
  1054. oc = &dss_cache.overlay_cache[ovl->id];
  1055. if (!oc->enabled)
  1056. continue;
  1057. dssdev = ovl->manager->device;
  1058. size = dispc_get_plane_fifo_size(ovl->id);
  1059. if (use_fifomerge)
  1060. size *= 3;
  1061. switch (dssdev->type) {
  1062. case OMAP_DISPLAY_TYPE_DPI:
  1063. case OMAP_DISPLAY_TYPE_DBI:
  1064. case OMAP_DISPLAY_TYPE_SDI:
  1065. case OMAP_DISPLAY_TYPE_VENC:
  1066. default_get_overlay_fifo_thresholds(ovl->id, size,
  1067. &oc->burst_size, &oc->fifo_low,
  1068. &oc->fifo_high);
  1069. break;
  1070. #ifdef CONFIG_OMAP2_DSS_DSI
  1071. case OMAP_DISPLAY_TYPE_DSI:
  1072. dsi_get_overlay_fifo_thresholds(ovl->id, size,
  1073. &oc->burst_size, &oc->fifo_low,
  1074. &oc->fifo_high);
  1075. break;
  1076. #endif
  1077. default:
  1078. BUG();
  1079. }
  1080. }
  1081. r = 0;
  1082. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
  1083. if (!dss_cache.irq_enabled) {
  1084. r = omap_dispc_register_isr(dss_apply_irq_handler, NULL,
  1085. DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
  1086. DISPC_IRQ_EVSYNC_EVEN);
  1087. dss_cache.irq_enabled = true;
  1088. }
  1089. configure_dispc();
  1090. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
  1091. spin_unlock_irqrestore(&dss_cache.lock, flags);
  1092. return r;
  1093. }
  1094. static int dss_check_manager(struct omap_overlay_manager *mgr)
  1095. {
  1096. /* OMAP supports only graphics source transparency color key and alpha
  1097. * blending simultaneously. See TRM 15.4.2.4.2.2 Alpha Mode */
  1098. if (mgr->info.alpha_enabled && mgr->info.trans_enabled &&
  1099. mgr->info.trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST)
  1100. return -EINVAL;
  1101. return 0;
  1102. }
  1103. static int omap_dss_mgr_set_info(struct omap_overlay_manager *mgr,
  1104. struct omap_overlay_manager_info *info)
  1105. {
  1106. int r;
  1107. struct omap_overlay_manager_info old_info;
  1108. old_info = mgr->info;
  1109. mgr->info = *info;
  1110. r = dss_check_manager(mgr);
  1111. if (r) {
  1112. mgr->info = old_info;
  1113. return r;
  1114. }
  1115. mgr->info_dirty = true;
  1116. return 0;
  1117. }
  1118. static void omap_dss_mgr_get_info(struct omap_overlay_manager *mgr,
  1119. struct omap_overlay_manager_info *info)
  1120. {
  1121. *info = mgr->info;
  1122. }
  1123. static int dss_mgr_enable(struct omap_overlay_manager *mgr)
  1124. {
  1125. dispc_enable_channel(mgr->id, 1);
  1126. return 0;
  1127. }
  1128. static int dss_mgr_disable(struct omap_overlay_manager *mgr)
  1129. {
  1130. dispc_enable_channel(mgr->id, 0);
  1131. return 0;
  1132. }
  1133. static void omap_dss_add_overlay_manager(struct omap_overlay_manager *manager)
  1134. {
  1135. ++num_managers;
  1136. list_add_tail(&manager->list, &manager_list);
  1137. }
  1138. int dss_init_overlay_managers(struct platform_device *pdev)
  1139. {
  1140. int i, r;
  1141. spin_lock_init(&dss_cache.lock);
  1142. INIT_LIST_HEAD(&manager_list);
  1143. num_managers = 0;
  1144. for (i = 0; i < 2; ++i) {
  1145. struct omap_overlay_manager *mgr;
  1146. mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
  1147. BUG_ON(mgr == NULL);
  1148. switch (i) {
  1149. case 0:
  1150. mgr->name = "lcd";
  1151. mgr->id = OMAP_DSS_CHANNEL_LCD;
  1152. mgr->supported_displays =
  1153. OMAP_DISPLAY_TYPE_DPI | OMAP_DISPLAY_TYPE_DBI |
  1154. OMAP_DISPLAY_TYPE_SDI | OMAP_DISPLAY_TYPE_DSI;
  1155. break;
  1156. case 1:
  1157. mgr->name = "tv";
  1158. mgr->id = OMAP_DSS_CHANNEL_DIGIT;
  1159. mgr->supported_displays = OMAP_DISPLAY_TYPE_VENC;
  1160. break;
  1161. }
  1162. mgr->set_device = &omap_dss_set_device;
  1163. mgr->unset_device = &omap_dss_unset_device;
  1164. mgr->apply = &omap_dss_mgr_apply;
  1165. mgr->set_manager_info = &omap_dss_mgr_set_info;
  1166. mgr->get_manager_info = &omap_dss_mgr_get_info;
  1167. mgr->wait_for_go = &dss_mgr_wait_for_go;
  1168. mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
  1169. mgr->enable = &dss_mgr_enable;
  1170. mgr->disable = &dss_mgr_disable;
  1171. mgr->caps = OMAP_DSS_OVL_MGR_CAP_DISPC;
  1172. dss_overlay_setup_dispc_manager(mgr);
  1173. omap_dss_add_overlay_manager(mgr);
  1174. r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
  1175. &pdev->dev.kobj, "manager%d", i);
  1176. if (r) {
  1177. DSSERR("failed to create sysfs file\n");
  1178. continue;
  1179. }
  1180. }
  1181. #ifdef L4_EXAMPLE
  1182. {
  1183. int omap_dss_mgr_apply_l4(struct omap_overlay_manager *mgr)
  1184. {
  1185. DSSDBG("omap_dss_mgr_apply_l4(%s)\n", mgr->name);
  1186. return 0;
  1187. }
  1188. struct omap_overlay_manager *mgr;
  1189. mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
  1190. BUG_ON(mgr == NULL);
  1191. mgr->name = "l4";
  1192. mgr->supported_displays =
  1193. OMAP_DISPLAY_TYPE_DBI | OMAP_DISPLAY_TYPE_DSI;
  1194. mgr->set_device = &omap_dss_set_device;
  1195. mgr->unset_device = &omap_dss_unset_device;
  1196. mgr->apply = &omap_dss_mgr_apply_l4;
  1197. mgr->set_manager_info = &omap_dss_mgr_set_info;
  1198. mgr->get_manager_info = &omap_dss_mgr_get_info;
  1199. dss_overlay_setup_l4_manager(mgr);
  1200. omap_dss_add_overlay_manager(mgr);
  1201. r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
  1202. &pdev->dev.kobj, "managerl4");
  1203. if (r)
  1204. DSSERR("failed to create sysfs file\n");
  1205. }
  1206. #endif
  1207. return 0;
  1208. }
  1209. void dss_uninit_overlay_managers(struct platform_device *pdev)
  1210. {
  1211. struct omap_overlay_manager *mgr;
  1212. while (!list_empty(&manager_list)) {
  1213. mgr = list_first_entry(&manager_list,
  1214. struct omap_overlay_manager, list);
  1215. list_del(&mgr->list);
  1216. kobject_del(&mgr->kobj);
  1217. kobject_put(&mgr->kobj);
  1218. kfree(mgr);
  1219. }
  1220. num_managers = 0;
  1221. }
  1222. int omap_dss_get_num_overlay_managers(void)
  1223. {
  1224. return num_managers;
  1225. }
  1226. EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
  1227. struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
  1228. {
  1229. int i = 0;
  1230. struct omap_overlay_manager *mgr;
  1231. list_for_each_entry(mgr, &manager_list, list) {
  1232. if (i++ == num)
  1233. return mgr;
  1234. }
  1235. return NULL;
  1236. }
  1237. EXPORT_SYMBOL(omap_dss_get_overlay_manager);