apply.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702
  1. /*
  2. * Copyright (C) 2011 Texas Instruments
  3. * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #define DSS_SUBSYS_NAME "APPLY"
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/slab.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/jiffies.h>
  23. #include <video/omapdss.h>
  24. #include "dss.h"
  25. #include "dss_features.h"
  26. #include "dispc-compat.h"
  27. /*
  28. * We have 4 levels of cache for the dispc settings. First two are in SW and
  29. * the latter two in HW.
  30. *
  31. * set_info()
  32. * v
  33. * +--------------------+
  34. * | user_info |
  35. * +--------------------+
  36. * v
  37. * apply()
  38. * v
  39. * +--------------------+
  40. * | info |
  41. * +--------------------+
  42. * v
  43. * write_regs()
  44. * v
  45. * +--------------------+
  46. * | shadow registers |
  47. * +--------------------+
  48. * v
  49. * VFP or lcd/digit_enable
  50. * v
  51. * +--------------------+
  52. * | registers |
  53. * +--------------------+
  54. */
  55. struct ovl_priv_data {
  56. bool user_info_dirty;
  57. struct omap_overlay_info user_info;
  58. bool info_dirty;
  59. struct omap_overlay_info info;
  60. bool shadow_info_dirty;
  61. bool extra_info_dirty;
  62. bool shadow_extra_info_dirty;
  63. bool enabled;
  64. u32 fifo_low, fifo_high;
  65. /*
  66. * True if overlay is to be enabled. Used to check and calculate configs
  67. * for the overlay before it is enabled in the HW.
  68. */
  69. bool enabling;
  70. };
  71. struct mgr_priv_data {
  72. bool user_info_dirty;
  73. struct omap_overlay_manager_info user_info;
  74. bool info_dirty;
  75. struct omap_overlay_manager_info info;
  76. bool shadow_info_dirty;
  77. /* If true, GO bit is up and shadow registers cannot be written.
  78. * Never true for manual update displays */
  79. bool busy;
  80. /* If true, dispc output is enabled */
  81. bool updating;
  82. /* If true, a display is enabled using this manager */
  83. bool enabled;
  84. bool extra_info_dirty;
  85. bool shadow_extra_info_dirty;
  86. struct omap_video_timings timings;
  87. struct dss_lcd_mgr_config lcd_config;
  88. void (*framedone_handler)(void *);
  89. void *framedone_handler_data;
  90. };
  91. static struct {
  92. struct ovl_priv_data ovl_priv_data_array[MAX_DSS_OVERLAYS];
  93. struct mgr_priv_data mgr_priv_data_array[MAX_DSS_MANAGERS];
  94. bool irq_enabled;
  95. } dss_data;
  96. /* protects dss_data */
  97. static spinlock_t data_lock;
  98. /* lock for blocking functions */
  99. static DEFINE_MUTEX(apply_lock);
  100. static DECLARE_COMPLETION(extra_updated_completion);
  101. static void dss_register_vsync_isr(void);
  102. static struct ovl_priv_data *get_ovl_priv(struct omap_overlay *ovl)
  103. {
  104. return &dss_data.ovl_priv_data_array[ovl->id];
  105. }
  106. static struct mgr_priv_data *get_mgr_priv(struct omap_overlay_manager *mgr)
  107. {
  108. return &dss_data.mgr_priv_data_array[mgr->id];
  109. }
  110. static void apply_init_priv(void)
  111. {
  112. const int num_ovls = dss_feat_get_num_ovls();
  113. struct mgr_priv_data *mp;
  114. int i;
  115. spin_lock_init(&data_lock);
  116. for (i = 0; i < num_ovls; ++i) {
  117. struct ovl_priv_data *op;
  118. op = &dss_data.ovl_priv_data_array[i];
  119. op->info.color_mode = OMAP_DSS_COLOR_RGB16;
  120. op->info.rotation_type = OMAP_DSS_ROT_DMA;
  121. op->info.global_alpha = 255;
  122. switch (i) {
  123. case 0:
  124. op->info.zorder = 0;
  125. break;
  126. case 1:
  127. op->info.zorder =
  128. dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 3 : 0;
  129. break;
  130. case 2:
  131. op->info.zorder =
  132. dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 2 : 0;
  133. break;
  134. case 3:
  135. op->info.zorder =
  136. dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 1 : 0;
  137. break;
  138. }
  139. op->user_info = op->info;
  140. }
  141. /*
  142. * Initialize some of the lcd_config fields for TV manager, this lets
  143. * us prevent checking if the manager is LCD or TV at some places
  144. */
  145. mp = &dss_data.mgr_priv_data_array[OMAP_DSS_CHANNEL_DIGIT];
  146. mp->lcd_config.video_port_width = 24;
  147. mp->lcd_config.clock_info.lck_div = 1;
  148. mp->lcd_config.clock_info.pck_div = 1;
  149. }
  150. /*
  151. * A LCD manager's stallmode decides whether it is in manual or auto update. TV
  152. * manager is always auto update, stallmode field for TV manager is false by
  153. * default
  154. */
  155. static bool ovl_manual_update(struct omap_overlay *ovl)
  156. {
  157. struct mgr_priv_data *mp = get_mgr_priv(ovl->manager);
  158. return mp->lcd_config.stallmode;
  159. }
  160. static bool mgr_manual_update(struct omap_overlay_manager *mgr)
  161. {
  162. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  163. return mp->lcd_config.stallmode;
  164. }
  165. static int dss_check_settings_low(struct omap_overlay_manager *mgr,
  166. bool applying)
  167. {
  168. struct omap_overlay_info *oi;
  169. struct omap_overlay_manager_info *mi;
  170. struct omap_overlay *ovl;
  171. struct omap_overlay_info *ois[MAX_DSS_OVERLAYS];
  172. struct ovl_priv_data *op;
  173. struct mgr_priv_data *mp;
  174. mp = get_mgr_priv(mgr);
  175. if (!mp->enabled)
  176. return 0;
  177. if (applying && mp->user_info_dirty)
  178. mi = &mp->user_info;
  179. else
  180. mi = &mp->info;
  181. /* collect the infos to be tested into the array */
  182. list_for_each_entry(ovl, &mgr->overlays, list) {
  183. op = get_ovl_priv(ovl);
  184. if (!op->enabled && !op->enabling)
  185. oi = NULL;
  186. else if (applying && op->user_info_dirty)
  187. oi = &op->user_info;
  188. else
  189. oi = &op->info;
  190. ois[ovl->id] = oi;
  191. }
  192. return dss_mgr_check(mgr, mi, &mp->timings, &mp->lcd_config, ois);
  193. }
  194. /*
  195. * check manager and overlay settings using overlay_info from data->info
  196. */
  197. static int dss_check_settings(struct omap_overlay_manager *mgr)
  198. {
  199. return dss_check_settings_low(mgr, false);
  200. }
  201. /*
  202. * check manager and overlay settings using overlay_info from ovl->info if
  203. * dirty and from data->info otherwise
  204. */
  205. static int dss_check_settings_apply(struct omap_overlay_manager *mgr)
  206. {
  207. return dss_check_settings_low(mgr, true);
  208. }
  209. static bool need_isr(void)
  210. {
  211. const int num_mgrs = dss_feat_get_num_mgrs();
  212. int i;
  213. for (i = 0; i < num_mgrs; ++i) {
  214. struct omap_overlay_manager *mgr;
  215. struct mgr_priv_data *mp;
  216. struct omap_overlay *ovl;
  217. mgr = omap_dss_get_overlay_manager(i);
  218. mp = get_mgr_priv(mgr);
  219. if (!mp->enabled)
  220. continue;
  221. if (mgr_manual_update(mgr)) {
  222. /* to catch FRAMEDONE */
  223. if (mp->updating)
  224. return true;
  225. } else {
  226. /* to catch GO bit going down */
  227. if (mp->busy)
  228. return true;
  229. /* to write new values to registers */
  230. if (mp->info_dirty)
  231. return true;
  232. /* to set GO bit */
  233. if (mp->shadow_info_dirty)
  234. return true;
  235. /*
  236. * NOTE: we don't check extra_info flags for disabled
  237. * managers, once the manager is enabled, the extra_info
  238. * related manager changes will be taken in by HW.
  239. */
  240. /* to write new values to registers */
  241. if (mp->extra_info_dirty)
  242. return true;
  243. /* to set GO bit */
  244. if (mp->shadow_extra_info_dirty)
  245. return true;
  246. list_for_each_entry(ovl, &mgr->overlays, list) {
  247. struct ovl_priv_data *op;
  248. op = get_ovl_priv(ovl);
  249. /*
  250. * NOTE: we check extra_info flags even for
  251. * disabled overlays, as extra_infos need to be
  252. * always written.
  253. */
  254. /* to write new values to registers */
  255. if (op->extra_info_dirty)
  256. return true;
  257. /* to set GO bit */
  258. if (op->shadow_extra_info_dirty)
  259. return true;
  260. if (!op->enabled)
  261. continue;
  262. /* to write new values to registers */
  263. if (op->info_dirty)
  264. return true;
  265. /* to set GO bit */
  266. if (op->shadow_info_dirty)
  267. return true;
  268. }
  269. }
  270. }
  271. return false;
  272. }
  273. static bool need_go(struct omap_overlay_manager *mgr)
  274. {
  275. struct omap_overlay *ovl;
  276. struct mgr_priv_data *mp;
  277. struct ovl_priv_data *op;
  278. mp = get_mgr_priv(mgr);
  279. if (mp->shadow_info_dirty || mp->shadow_extra_info_dirty)
  280. return true;
  281. list_for_each_entry(ovl, &mgr->overlays, list) {
  282. op = get_ovl_priv(ovl);
  283. if (op->shadow_info_dirty || op->shadow_extra_info_dirty)
  284. return true;
  285. }
  286. return false;
  287. }
  288. /* returns true if an extra_info field is currently being updated */
  289. static bool extra_info_update_ongoing(void)
  290. {
  291. const int num_mgrs = dss_feat_get_num_mgrs();
  292. int i;
  293. for (i = 0; i < num_mgrs; ++i) {
  294. struct omap_overlay_manager *mgr;
  295. struct omap_overlay *ovl;
  296. struct mgr_priv_data *mp;
  297. mgr = omap_dss_get_overlay_manager(i);
  298. mp = get_mgr_priv(mgr);
  299. if (!mp->enabled)
  300. continue;
  301. if (!mp->updating)
  302. continue;
  303. if (mp->extra_info_dirty || mp->shadow_extra_info_dirty)
  304. return true;
  305. list_for_each_entry(ovl, &mgr->overlays, list) {
  306. struct ovl_priv_data *op = get_ovl_priv(ovl);
  307. if (op->extra_info_dirty || op->shadow_extra_info_dirty)
  308. return true;
  309. }
  310. }
  311. return false;
  312. }
  313. /* wait until no extra_info updates are pending */
  314. static void wait_pending_extra_info_updates(void)
  315. {
  316. bool updating;
  317. unsigned long flags;
  318. unsigned long t;
  319. int r;
  320. spin_lock_irqsave(&data_lock, flags);
  321. updating = extra_info_update_ongoing();
  322. if (!updating) {
  323. spin_unlock_irqrestore(&data_lock, flags);
  324. return;
  325. }
  326. init_completion(&extra_updated_completion);
  327. spin_unlock_irqrestore(&data_lock, flags);
  328. t = msecs_to_jiffies(500);
  329. r = wait_for_completion_timeout(&extra_updated_completion, t);
  330. if (r == 0)
  331. DSSWARN("timeout in wait_pending_extra_info_updates\n");
  332. }
  333. static struct omap_dss_device *dss_mgr_get_device(struct omap_overlay_manager *mgr)
  334. {
  335. struct omap_dss_device *dssdev;
  336. dssdev = mgr->output;
  337. if (dssdev == NULL)
  338. return NULL;
  339. while (dssdev->dst)
  340. dssdev = dssdev->dst;
  341. if (dssdev->driver)
  342. return dssdev;
  343. else
  344. return NULL;
  345. }
  346. static struct omap_dss_device *dss_ovl_get_device(struct omap_overlay *ovl)
  347. {
  348. return ovl->manager ? dss_mgr_get_device(ovl->manager) : NULL;
  349. }
  350. static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
  351. {
  352. unsigned long timeout = msecs_to_jiffies(500);
  353. u32 irq;
  354. int r;
  355. if (mgr->output == NULL)
  356. return -ENODEV;
  357. r = dispc_runtime_get();
  358. if (r)
  359. return r;
  360. switch (mgr->output->id) {
  361. case OMAP_DSS_OUTPUT_VENC:
  362. irq = DISPC_IRQ_EVSYNC_ODD;
  363. break;
  364. case OMAP_DSS_OUTPUT_HDMI:
  365. irq = DISPC_IRQ_EVSYNC_EVEN;
  366. break;
  367. default:
  368. irq = dispc_mgr_get_vsync_irq(mgr->id);
  369. break;
  370. }
  371. r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
  372. dispc_runtime_put();
  373. return r;
  374. }
  375. static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
  376. {
  377. unsigned long timeout = msecs_to_jiffies(500);
  378. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  379. u32 irq;
  380. unsigned long flags;
  381. int r;
  382. int i;
  383. spin_lock_irqsave(&data_lock, flags);
  384. if (mgr_manual_update(mgr)) {
  385. spin_unlock_irqrestore(&data_lock, flags);
  386. return 0;
  387. }
  388. if (!mp->enabled) {
  389. spin_unlock_irqrestore(&data_lock, flags);
  390. return 0;
  391. }
  392. spin_unlock_irqrestore(&data_lock, flags);
  393. r = dispc_runtime_get();
  394. if (r)
  395. return r;
  396. irq = dispc_mgr_get_vsync_irq(mgr->id);
  397. i = 0;
  398. while (1) {
  399. bool shadow_dirty, dirty;
  400. spin_lock_irqsave(&data_lock, flags);
  401. dirty = mp->info_dirty;
  402. shadow_dirty = mp->shadow_info_dirty;
  403. spin_unlock_irqrestore(&data_lock, flags);
  404. if (!dirty && !shadow_dirty) {
  405. r = 0;
  406. break;
  407. }
  408. /* 4 iterations is the worst case:
  409. * 1 - initial iteration, dirty = true (between VFP and VSYNC)
  410. * 2 - first VSYNC, dirty = true
  411. * 3 - dirty = false, shadow_dirty = true
  412. * 4 - shadow_dirty = false */
  413. if (i++ == 3) {
  414. DSSERR("mgr(%d)->wait_for_go() not finishing\n",
  415. mgr->id);
  416. r = 0;
  417. break;
  418. }
  419. r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
  420. if (r == -ERESTARTSYS)
  421. break;
  422. if (r) {
  423. DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
  424. break;
  425. }
  426. }
  427. dispc_runtime_put();
  428. return r;
  429. }
  430. static int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
  431. {
  432. unsigned long timeout = msecs_to_jiffies(500);
  433. struct ovl_priv_data *op;
  434. struct mgr_priv_data *mp;
  435. u32 irq;
  436. unsigned long flags;
  437. int r;
  438. int i;
  439. if (!ovl->manager)
  440. return 0;
  441. mp = get_mgr_priv(ovl->manager);
  442. spin_lock_irqsave(&data_lock, flags);
  443. if (ovl_manual_update(ovl)) {
  444. spin_unlock_irqrestore(&data_lock, flags);
  445. return 0;
  446. }
  447. if (!mp->enabled) {
  448. spin_unlock_irqrestore(&data_lock, flags);
  449. return 0;
  450. }
  451. spin_unlock_irqrestore(&data_lock, flags);
  452. r = dispc_runtime_get();
  453. if (r)
  454. return r;
  455. irq = dispc_mgr_get_vsync_irq(ovl->manager->id);
  456. op = get_ovl_priv(ovl);
  457. i = 0;
  458. while (1) {
  459. bool shadow_dirty, dirty;
  460. spin_lock_irqsave(&data_lock, flags);
  461. dirty = op->info_dirty;
  462. shadow_dirty = op->shadow_info_dirty;
  463. spin_unlock_irqrestore(&data_lock, flags);
  464. if (!dirty && !shadow_dirty) {
  465. r = 0;
  466. break;
  467. }
  468. /* 4 iterations is the worst case:
  469. * 1 - initial iteration, dirty = true (between VFP and VSYNC)
  470. * 2 - first VSYNC, dirty = true
  471. * 3 - dirty = false, shadow_dirty = true
  472. * 4 - shadow_dirty = false */
  473. if (i++ == 3) {
  474. DSSERR("ovl(%d)->wait_for_go() not finishing\n",
  475. ovl->id);
  476. r = 0;
  477. break;
  478. }
  479. r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
  480. if (r == -ERESTARTSYS)
  481. break;
  482. if (r) {
  483. DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
  484. break;
  485. }
  486. }
  487. dispc_runtime_put();
  488. return r;
  489. }
  490. static void dss_ovl_write_regs(struct omap_overlay *ovl)
  491. {
  492. struct ovl_priv_data *op = get_ovl_priv(ovl);
  493. struct omap_overlay_info *oi;
  494. bool replication;
  495. struct mgr_priv_data *mp;
  496. int r;
  497. DSSDBG("writing ovl %d regs\n", ovl->id);
  498. if (!op->enabled || !op->info_dirty)
  499. return;
  500. oi = &op->info;
  501. mp = get_mgr_priv(ovl->manager);
  502. replication = dss_ovl_use_replication(mp->lcd_config, oi->color_mode);
  503. r = dispc_ovl_setup(ovl->id, oi, replication, &mp->timings, false);
  504. if (r) {
  505. /*
  506. * We can't do much here, as this function can be called from
  507. * vsync interrupt.
  508. */
  509. DSSERR("dispc_ovl_setup failed for ovl %d\n", ovl->id);
  510. /* This will leave fifo configurations in a nonoptimal state */
  511. op->enabled = false;
  512. dispc_ovl_enable(ovl->id, false);
  513. return;
  514. }
  515. op->info_dirty = false;
  516. if (mp->updating)
  517. op->shadow_info_dirty = true;
  518. }
  519. static void dss_ovl_write_regs_extra(struct omap_overlay *ovl)
  520. {
  521. struct ovl_priv_data *op = get_ovl_priv(ovl);
  522. struct mgr_priv_data *mp;
  523. DSSDBG("writing ovl %d regs extra\n", ovl->id);
  524. if (!op->extra_info_dirty)
  525. return;
  526. /* note: write also when op->enabled == false, so that the ovl gets
  527. * disabled */
  528. dispc_ovl_enable(ovl->id, op->enabled);
  529. dispc_ovl_set_fifo_threshold(ovl->id, op->fifo_low, op->fifo_high);
  530. mp = get_mgr_priv(ovl->manager);
  531. op->extra_info_dirty = false;
  532. if (mp->updating)
  533. op->shadow_extra_info_dirty = true;
  534. }
  535. static void dss_mgr_write_regs(struct omap_overlay_manager *mgr)
  536. {
  537. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  538. struct omap_overlay *ovl;
  539. DSSDBG("writing mgr %d regs\n", mgr->id);
  540. if (!mp->enabled)
  541. return;
  542. WARN_ON(mp->busy);
  543. /* Commit overlay settings */
  544. list_for_each_entry(ovl, &mgr->overlays, list) {
  545. dss_ovl_write_regs(ovl);
  546. dss_ovl_write_regs_extra(ovl);
  547. }
  548. if (mp->info_dirty) {
  549. dispc_mgr_setup(mgr->id, &mp->info);
  550. mp->info_dirty = false;
  551. if (mp->updating)
  552. mp->shadow_info_dirty = true;
  553. }
  554. }
  555. static void dss_mgr_write_regs_extra(struct omap_overlay_manager *mgr)
  556. {
  557. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  558. DSSDBG("writing mgr %d regs extra\n", mgr->id);
  559. if (!mp->extra_info_dirty)
  560. return;
  561. dispc_mgr_set_timings(mgr->id, &mp->timings);
  562. /* lcd_config parameters */
  563. if (dss_mgr_is_lcd(mgr->id))
  564. dispc_mgr_set_lcd_config(mgr->id, &mp->lcd_config);
  565. mp->extra_info_dirty = false;
  566. if (mp->updating)
  567. mp->shadow_extra_info_dirty = true;
  568. }
  569. static void dss_write_regs(void)
  570. {
  571. const int num_mgrs = omap_dss_get_num_overlay_managers();
  572. int i;
  573. for (i = 0; i < num_mgrs; ++i) {
  574. struct omap_overlay_manager *mgr;
  575. struct mgr_priv_data *mp;
  576. int r;
  577. mgr = omap_dss_get_overlay_manager(i);
  578. mp = get_mgr_priv(mgr);
  579. if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
  580. continue;
  581. r = dss_check_settings(mgr);
  582. if (r) {
  583. DSSERR("cannot write registers for manager %s: "
  584. "illegal configuration\n", mgr->name);
  585. continue;
  586. }
  587. dss_mgr_write_regs(mgr);
  588. dss_mgr_write_regs_extra(mgr);
  589. }
  590. }
  591. static void dss_set_go_bits(void)
  592. {
  593. const int num_mgrs = omap_dss_get_num_overlay_managers();
  594. int i;
  595. for (i = 0; i < num_mgrs; ++i) {
  596. struct omap_overlay_manager *mgr;
  597. struct mgr_priv_data *mp;
  598. mgr = omap_dss_get_overlay_manager(i);
  599. mp = get_mgr_priv(mgr);
  600. if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
  601. continue;
  602. if (!need_go(mgr))
  603. continue;
  604. mp->busy = true;
  605. if (!dss_data.irq_enabled && need_isr())
  606. dss_register_vsync_isr();
  607. dispc_mgr_go(mgr->id);
  608. }
  609. }
  610. static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
  611. {
  612. struct omap_overlay *ovl;
  613. struct mgr_priv_data *mp;
  614. struct ovl_priv_data *op;
  615. mp = get_mgr_priv(mgr);
  616. mp->shadow_info_dirty = false;
  617. mp->shadow_extra_info_dirty = false;
  618. list_for_each_entry(ovl, &mgr->overlays, list) {
  619. op = get_ovl_priv(ovl);
  620. op->shadow_info_dirty = false;
  621. op->shadow_extra_info_dirty = false;
  622. }
  623. }
  624. static int dss_mgr_connect_compat(struct omap_overlay_manager *mgr,
  625. struct omap_dss_device *dst)
  626. {
  627. return mgr->set_output(mgr, dst);
  628. }
  629. static void dss_mgr_disconnect_compat(struct omap_overlay_manager *mgr,
  630. struct omap_dss_device *dst)
  631. {
  632. mgr->unset_output(mgr);
  633. }
  634. static void dss_mgr_start_update_compat(struct omap_overlay_manager *mgr)
  635. {
  636. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  637. unsigned long flags;
  638. int r;
  639. spin_lock_irqsave(&data_lock, flags);
  640. WARN_ON(mp->updating);
  641. r = dss_check_settings(mgr);
  642. if (r) {
  643. DSSERR("cannot start manual update: illegal configuration\n");
  644. spin_unlock_irqrestore(&data_lock, flags);
  645. return;
  646. }
  647. dss_mgr_write_regs(mgr);
  648. dss_mgr_write_regs_extra(mgr);
  649. mp->updating = true;
  650. if (!dss_data.irq_enabled && need_isr())
  651. dss_register_vsync_isr();
  652. dispc_mgr_enable_sync(mgr->id);
  653. spin_unlock_irqrestore(&data_lock, flags);
  654. }
  655. static void dss_apply_irq_handler(void *data, u32 mask);
  656. static void dss_register_vsync_isr(void)
  657. {
  658. const int num_mgrs = dss_feat_get_num_mgrs();
  659. u32 mask;
  660. int r, i;
  661. mask = 0;
  662. for (i = 0; i < num_mgrs; ++i)
  663. mask |= dispc_mgr_get_vsync_irq(i);
  664. for (i = 0; i < num_mgrs; ++i)
  665. mask |= dispc_mgr_get_framedone_irq(i);
  666. r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
  667. WARN_ON(r);
  668. dss_data.irq_enabled = true;
  669. }
  670. static void dss_unregister_vsync_isr(void)
  671. {
  672. const int num_mgrs = dss_feat_get_num_mgrs();
  673. u32 mask;
  674. int r, i;
  675. mask = 0;
  676. for (i = 0; i < num_mgrs; ++i)
  677. mask |= dispc_mgr_get_vsync_irq(i);
  678. for (i = 0; i < num_mgrs; ++i)
  679. mask |= dispc_mgr_get_framedone_irq(i);
  680. r = omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, mask);
  681. WARN_ON(r);
  682. dss_data.irq_enabled = false;
  683. }
  684. static void dss_apply_irq_handler(void *data, u32 mask)
  685. {
  686. const int num_mgrs = dss_feat_get_num_mgrs();
  687. int i;
  688. bool extra_updating;
  689. spin_lock(&data_lock);
  690. /* clear busy, updating flags, shadow_dirty flags */
  691. for (i = 0; i < num_mgrs; i++) {
  692. struct omap_overlay_manager *mgr;
  693. struct mgr_priv_data *mp;
  694. mgr = omap_dss_get_overlay_manager(i);
  695. mp = get_mgr_priv(mgr);
  696. if (!mp->enabled)
  697. continue;
  698. mp->updating = dispc_mgr_is_enabled(i);
  699. if (!mgr_manual_update(mgr)) {
  700. bool was_busy = mp->busy;
  701. mp->busy = dispc_mgr_go_busy(i);
  702. if (was_busy && !mp->busy)
  703. mgr_clear_shadow_dirty(mgr);
  704. }
  705. }
  706. dss_write_regs();
  707. dss_set_go_bits();
  708. extra_updating = extra_info_update_ongoing();
  709. if (!extra_updating)
  710. complete_all(&extra_updated_completion);
  711. /* call framedone handlers for manual update displays */
  712. for (i = 0; i < num_mgrs; i++) {
  713. struct omap_overlay_manager *mgr;
  714. struct mgr_priv_data *mp;
  715. mgr = omap_dss_get_overlay_manager(i);
  716. mp = get_mgr_priv(mgr);
  717. if (!mgr_manual_update(mgr) || !mp->framedone_handler)
  718. continue;
  719. if (mask & dispc_mgr_get_framedone_irq(i))
  720. mp->framedone_handler(mp->framedone_handler_data);
  721. }
  722. if (!need_isr())
  723. dss_unregister_vsync_isr();
  724. spin_unlock(&data_lock);
  725. }
  726. static void omap_dss_mgr_apply_ovl(struct omap_overlay *ovl)
  727. {
  728. struct ovl_priv_data *op;
  729. op = get_ovl_priv(ovl);
  730. if (!op->user_info_dirty)
  731. return;
  732. op->user_info_dirty = false;
  733. op->info_dirty = true;
  734. op->info = op->user_info;
  735. }
  736. static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr)
  737. {
  738. struct mgr_priv_data *mp;
  739. mp = get_mgr_priv(mgr);
  740. if (!mp->user_info_dirty)
  741. return;
  742. mp->user_info_dirty = false;
  743. mp->info_dirty = true;
  744. mp->info = mp->user_info;
  745. }
  746. static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
  747. {
  748. unsigned long flags;
  749. struct omap_overlay *ovl;
  750. int r;
  751. DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
  752. spin_lock_irqsave(&data_lock, flags);
  753. r = dss_check_settings_apply(mgr);
  754. if (r) {
  755. spin_unlock_irqrestore(&data_lock, flags);
  756. DSSERR("failed to apply settings: illegal configuration.\n");
  757. return r;
  758. }
  759. /* Configure overlays */
  760. list_for_each_entry(ovl, &mgr->overlays, list)
  761. omap_dss_mgr_apply_ovl(ovl);
  762. /* Configure manager */
  763. omap_dss_mgr_apply_mgr(mgr);
  764. dss_write_regs();
  765. dss_set_go_bits();
  766. spin_unlock_irqrestore(&data_lock, flags);
  767. return 0;
  768. }
  769. static void dss_apply_ovl_enable(struct omap_overlay *ovl, bool enable)
  770. {
  771. struct ovl_priv_data *op;
  772. op = get_ovl_priv(ovl);
  773. if (op->enabled == enable)
  774. return;
  775. op->enabled = enable;
  776. op->extra_info_dirty = true;
  777. }
  778. static void dss_apply_ovl_fifo_thresholds(struct omap_overlay *ovl,
  779. u32 fifo_low, u32 fifo_high)
  780. {
  781. struct ovl_priv_data *op = get_ovl_priv(ovl);
  782. if (op->fifo_low == fifo_low && op->fifo_high == fifo_high)
  783. return;
  784. op->fifo_low = fifo_low;
  785. op->fifo_high = fifo_high;
  786. op->extra_info_dirty = true;
  787. }
  788. static void dss_ovl_setup_fifo(struct omap_overlay *ovl)
  789. {
  790. struct ovl_priv_data *op = get_ovl_priv(ovl);
  791. u32 fifo_low, fifo_high;
  792. bool use_fifo_merge = false;
  793. if (!op->enabled && !op->enabling)
  794. return;
  795. dispc_ovl_compute_fifo_thresholds(ovl->id, &fifo_low, &fifo_high,
  796. use_fifo_merge, ovl_manual_update(ovl));
  797. dss_apply_ovl_fifo_thresholds(ovl, fifo_low, fifo_high);
  798. }
  799. static void dss_mgr_setup_fifos(struct omap_overlay_manager *mgr)
  800. {
  801. struct omap_overlay *ovl;
  802. struct mgr_priv_data *mp;
  803. mp = get_mgr_priv(mgr);
  804. if (!mp->enabled)
  805. return;
  806. list_for_each_entry(ovl, &mgr->overlays, list)
  807. dss_ovl_setup_fifo(ovl);
  808. }
  809. static void dss_setup_fifos(void)
  810. {
  811. const int num_mgrs = omap_dss_get_num_overlay_managers();
  812. struct omap_overlay_manager *mgr;
  813. int i;
  814. for (i = 0; i < num_mgrs; ++i) {
  815. mgr = omap_dss_get_overlay_manager(i);
  816. dss_mgr_setup_fifos(mgr);
  817. }
  818. }
  819. static int dss_mgr_enable_compat(struct omap_overlay_manager *mgr)
  820. {
  821. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  822. unsigned long flags;
  823. int r;
  824. mutex_lock(&apply_lock);
  825. if (mp->enabled)
  826. goto out;
  827. spin_lock_irqsave(&data_lock, flags);
  828. mp->enabled = true;
  829. r = dss_check_settings(mgr);
  830. if (r) {
  831. DSSERR("failed to enable manager %d: check_settings failed\n",
  832. mgr->id);
  833. goto err;
  834. }
  835. dss_setup_fifos();
  836. dss_write_regs();
  837. dss_set_go_bits();
  838. if (!mgr_manual_update(mgr))
  839. mp->updating = true;
  840. if (!dss_data.irq_enabled && need_isr())
  841. dss_register_vsync_isr();
  842. spin_unlock_irqrestore(&data_lock, flags);
  843. if (!mgr_manual_update(mgr))
  844. dispc_mgr_enable_sync(mgr->id);
  845. out:
  846. mutex_unlock(&apply_lock);
  847. return 0;
  848. err:
  849. mp->enabled = false;
  850. spin_unlock_irqrestore(&data_lock, flags);
  851. mutex_unlock(&apply_lock);
  852. return r;
  853. }
  854. static void dss_mgr_disable_compat(struct omap_overlay_manager *mgr)
  855. {
  856. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  857. unsigned long flags;
  858. mutex_lock(&apply_lock);
  859. if (!mp->enabled)
  860. goto out;
  861. wait_pending_extra_info_updates();
  862. if (!mgr_manual_update(mgr))
  863. dispc_mgr_disable_sync(mgr->id);
  864. spin_lock_irqsave(&data_lock, flags);
  865. mp->updating = false;
  866. mp->enabled = false;
  867. spin_unlock_irqrestore(&data_lock, flags);
  868. out:
  869. mutex_unlock(&apply_lock);
  870. }
  871. static int dss_mgr_set_info(struct omap_overlay_manager *mgr,
  872. struct omap_overlay_manager_info *info)
  873. {
  874. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  875. unsigned long flags;
  876. int r;
  877. r = dss_mgr_simple_check(mgr, info);
  878. if (r)
  879. return r;
  880. spin_lock_irqsave(&data_lock, flags);
  881. mp->user_info = *info;
  882. mp->user_info_dirty = true;
  883. spin_unlock_irqrestore(&data_lock, flags);
  884. return 0;
  885. }
  886. static void dss_mgr_get_info(struct omap_overlay_manager *mgr,
  887. struct omap_overlay_manager_info *info)
  888. {
  889. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  890. unsigned long flags;
  891. spin_lock_irqsave(&data_lock, flags);
  892. *info = mp->user_info;
  893. spin_unlock_irqrestore(&data_lock, flags);
  894. }
  895. static int dss_mgr_set_output(struct omap_overlay_manager *mgr,
  896. struct omap_dss_device *output)
  897. {
  898. int r;
  899. mutex_lock(&apply_lock);
  900. if (mgr->output) {
  901. DSSERR("manager %s is already connected to an output\n",
  902. mgr->name);
  903. r = -EINVAL;
  904. goto err;
  905. }
  906. if ((mgr->supported_outputs & output->id) == 0) {
  907. DSSERR("output does not support manager %s\n",
  908. mgr->name);
  909. r = -EINVAL;
  910. goto err;
  911. }
  912. output->manager = mgr;
  913. mgr->output = output;
  914. mutex_unlock(&apply_lock);
  915. return 0;
  916. err:
  917. mutex_unlock(&apply_lock);
  918. return r;
  919. }
  920. static int dss_mgr_unset_output(struct omap_overlay_manager *mgr)
  921. {
  922. int r;
  923. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  924. unsigned long flags;
  925. mutex_lock(&apply_lock);
  926. if (!mgr->output) {
  927. DSSERR("failed to unset output, output not set\n");
  928. r = -EINVAL;
  929. goto err;
  930. }
  931. spin_lock_irqsave(&data_lock, flags);
  932. if (mp->enabled) {
  933. DSSERR("output can't be unset when manager is enabled\n");
  934. r = -EINVAL;
  935. goto err1;
  936. }
  937. spin_unlock_irqrestore(&data_lock, flags);
  938. mgr->output->manager = NULL;
  939. mgr->output = NULL;
  940. mutex_unlock(&apply_lock);
  941. return 0;
  942. err1:
  943. spin_unlock_irqrestore(&data_lock, flags);
  944. err:
  945. mutex_unlock(&apply_lock);
  946. return r;
  947. }
  948. static void dss_apply_mgr_timings(struct omap_overlay_manager *mgr,
  949. const struct omap_video_timings *timings)
  950. {
  951. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  952. mp->timings = *timings;
  953. mp->extra_info_dirty = true;
  954. }
  955. static void dss_mgr_set_timings_compat(struct omap_overlay_manager *mgr,
  956. const struct omap_video_timings *timings)
  957. {
  958. unsigned long flags;
  959. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  960. spin_lock_irqsave(&data_lock, flags);
  961. if (mp->updating) {
  962. DSSERR("cannot set timings for %s: manager needs to be disabled\n",
  963. mgr->name);
  964. goto out;
  965. }
  966. dss_apply_mgr_timings(mgr, timings);
  967. out:
  968. spin_unlock_irqrestore(&data_lock, flags);
  969. }
  970. static void dss_apply_mgr_lcd_config(struct omap_overlay_manager *mgr,
  971. const struct dss_lcd_mgr_config *config)
  972. {
  973. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  974. mp->lcd_config = *config;
  975. mp->extra_info_dirty = true;
  976. }
  977. static void dss_mgr_set_lcd_config_compat(struct omap_overlay_manager *mgr,
  978. const struct dss_lcd_mgr_config *config)
  979. {
  980. unsigned long flags;
  981. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  982. spin_lock_irqsave(&data_lock, flags);
  983. if (mp->enabled) {
  984. DSSERR("cannot apply lcd config for %s: manager needs to be disabled\n",
  985. mgr->name);
  986. goto out;
  987. }
  988. dss_apply_mgr_lcd_config(mgr, config);
  989. out:
  990. spin_unlock_irqrestore(&data_lock, flags);
  991. }
  992. static int dss_ovl_set_info(struct omap_overlay *ovl,
  993. struct omap_overlay_info *info)
  994. {
  995. struct ovl_priv_data *op = get_ovl_priv(ovl);
  996. unsigned long flags;
  997. int r;
  998. r = dss_ovl_simple_check(ovl, info);
  999. if (r)
  1000. return r;
  1001. spin_lock_irqsave(&data_lock, flags);
  1002. op->user_info = *info;
  1003. op->user_info_dirty = true;
  1004. spin_unlock_irqrestore(&data_lock, flags);
  1005. return 0;
  1006. }
  1007. static void dss_ovl_get_info(struct omap_overlay *ovl,
  1008. struct omap_overlay_info *info)
  1009. {
  1010. struct ovl_priv_data *op = get_ovl_priv(ovl);
  1011. unsigned long flags;
  1012. spin_lock_irqsave(&data_lock, flags);
  1013. *info = op->user_info;
  1014. spin_unlock_irqrestore(&data_lock, flags);
  1015. }
  1016. static int dss_ovl_set_manager(struct omap_overlay *ovl,
  1017. struct omap_overlay_manager *mgr)
  1018. {
  1019. struct ovl_priv_data *op = get_ovl_priv(ovl);
  1020. unsigned long flags;
  1021. int r;
  1022. if (!mgr)
  1023. return -EINVAL;
  1024. mutex_lock(&apply_lock);
  1025. if (ovl->manager) {
  1026. DSSERR("overlay '%s' already has a manager '%s'\n",
  1027. ovl->name, ovl->manager->name);
  1028. r = -EINVAL;
  1029. goto err;
  1030. }
  1031. r = dispc_runtime_get();
  1032. if (r)
  1033. goto err;
  1034. spin_lock_irqsave(&data_lock, flags);
  1035. if (op->enabled) {
  1036. spin_unlock_irqrestore(&data_lock, flags);
  1037. DSSERR("overlay has to be disabled to change the manager\n");
  1038. r = -EINVAL;
  1039. goto err1;
  1040. }
  1041. dispc_ovl_set_channel_out(ovl->id, mgr->id);
  1042. ovl->manager = mgr;
  1043. list_add_tail(&ovl->list, &mgr->overlays);
  1044. spin_unlock_irqrestore(&data_lock, flags);
  1045. dispc_runtime_put();
  1046. mutex_unlock(&apply_lock);
  1047. return 0;
  1048. err1:
  1049. dispc_runtime_put();
  1050. err:
  1051. mutex_unlock(&apply_lock);
  1052. return r;
  1053. }
  1054. static int dss_ovl_unset_manager(struct omap_overlay *ovl)
  1055. {
  1056. struct ovl_priv_data *op = get_ovl_priv(ovl);
  1057. unsigned long flags;
  1058. int r;
  1059. mutex_lock(&apply_lock);
  1060. if (!ovl->manager) {
  1061. DSSERR("failed to detach overlay: manager not set\n");
  1062. r = -EINVAL;
  1063. goto err;
  1064. }
  1065. spin_lock_irqsave(&data_lock, flags);
  1066. if (op->enabled) {
  1067. spin_unlock_irqrestore(&data_lock, flags);
  1068. DSSERR("overlay has to be disabled to unset the manager\n");
  1069. r = -EINVAL;
  1070. goto err;
  1071. }
  1072. spin_unlock_irqrestore(&data_lock, flags);
  1073. /* wait for pending extra_info updates to ensure the ovl is disabled */
  1074. wait_pending_extra_info_updates();
  1075. /*
  1076. * For a manual update display, there is no guarantee that the overlay
  1077. * is really disabled in HW, we may need an extra update from this
  1078. * manager before the configurations can go in. Return an error if the
  1079. * overlay needed an update from the manager.
  1080. *
  1081. * TODO: Instead of returning an error, try to do a dummy manager update
  1082. * here to disable the overlay in hardware. Use the *GATED fields in
  1083. * the DISPC_CONFIG registers to do a dummy update.
  1084. */
  1085. spin_lock_irqsave(&data_lock, flags);
  1086. if (ovl_manual_update(ovl) && op->extra_info_dirty) {
  1087. spin_unlock_irqrestore(&data_lock, flags);
  1088. DSSERR("need an update to change the manager\n");
  1089. r = -EINVAL;
  1090. goto err;
  1091. }
  1092. ovl->manager = NULL;
  1093. list_del(&ovl->list);
  1094. spin_unlock_irqrestore(&data_lock, flags);
  1095. mutex_unlock(&apply_lock);
  1096. return 0;
  1097. err:
  1098. mutex_unlock(&apply_lock);
  1099. return r;
  1100. }
  1101. static bool dss_ovl_is_enabled(struct omap_overlay *ovl)
  1102. {
  1103. struct ovl_priv_data *op = get_ovl_priv(ovl);
  1104. unsigned long flags;
  1105. bool e;
  1106. spin_lock_irqsave(&data_lock, flags);
  1107. e = op->enabled;
  1108. spin_unlock_irqrestore(&data_lock, flags);
  1109. return e;
  1110. }
  1111. static int dss_ovl_enable(struct omap_overlay *ovl)
  1112. {
  1113. struct ovl_priv_data *op = get_ovl_priv(ovl);
  1114. unsigned long flags;
  1115. int r;
  1116. mutex_lock(&apply_lock);
  1117. if (op->enabled) {
  1118. r = 0;
  1119. goto err1;
  1120. }
  1121. if (ovl->manager == NULL || ovl->manager->output == NULL) {
  1122. r = -EINVAL;
  1123. goto err1;
  1124. }
  1125. spin_lock_irqsave(&data_lock, flags);
  1126. op->enabling = true;
  1127. r = dss_check_settings(ovl->manager);
  1128. if (r) {
  1129. DSSERR("failed to enable overlay %d: check_settings failed\n",
  1130. ovl->id);
  1131. goto err2;
  1132. }
  1133. dss_setup_fifos();
  1134. op->enabling = false;
  1135. dss_apply_ovl_enable(ovl, true);
  1136. dss_write_regs();
  1137. dss_set_go_bits();
  1138. spin_unlock_irqrestore(&data_lock, flags);
  1139. mutex_unlock(&apply_lock);
  1140. return 0;
  1141. err2:
  1142. op->enabling = false;
  1143. spin_unlock_irqrestore(&data_lock, flags);
  1144. err1:
  1145. mutex_unlock(&apply_lock);
  1146. return r;
  1147. }
  1148. static int dss_ovl_disable(struct omap_overlay *ovl)
  1149. {
  1150. struct ovl_priv_data *op = get_ovl_priv(ovl);
  1151. unsigned long flags;
  1152. int r;
  1153. mutex_lock(&apply_lock);
  1154. if (!op->enabled) {
  1155. r = 0;
  1156. goto err;
  1157. }
  1158. if (ovl->manager == NULL || ovl->manager->output == NULL) {
  1159. r = -EINVAL;
  1160. goto err;
  1161. }
  1162. spin_lock_irqsave(&data_lock, flags);
  1163. dss_apply_ovl_enable(ovl, false);
  1164. dss_write_regs();
  1165. dss_set_go_bits();
  1166. spin_unlock_irqrestore(&data_lock, flags);
  1167. mutex_unlock(&apply_lock);
  1168. return 0;
  1169. err:
  1170. mutex_unlock(&apply_lock);
  1171. return r;
  1172. }
  1173. static int dss_mgr_register_framedone_handler_compat(struct omap_overlay_manager *mgr,
  1174. void (*handler)(void *), void *data)
  1175. {
  1176. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  1177. if (mp->framedone_handler)
  1178. return -EBUSY;
  1179. mp->framedone_handler = handler;
  1180. mp->framedone_handler_data = data;
  1181. return 0;
  1182. }
  1183. static void dss_mgr_unregister_framedone_handler_compat(struct omap_overlay_manager *mgr,
  1184. void (*handler)(void *), void *data)
  1185. {
  1186. struct mgr_priv_data *mp = get_mgr_priv(mgr);
  1187. WARN_ON(mp->framedone_handler != handler ||
  1188. mp->framedone_handler_data != data);
  1189. mp->framedone_handler = NULL;
  1190. mp->framedone_handler_data = NULL;
  1191. }
  1192. static const struct dss_mgr_ops apply_mgr_ops = {
  1193. .connect = dss_mgr_connect_compat,
  1194. .disconnect = dss_mgr_disconnect_compat,
  1195. .start_update = dss_mgr_start_update_compat,
  1196. .enable = dss_mgr_enable_compat,
  1197. .disable = dss_mgr_disable_compat,
  1198. .set_timings = dss_mgr_set_timings_compat,
  1199. .set_lcd_config = dss_mgr_set_lcd_config_compat,
  1200. .register_framedone_handler = dss_mgr_register_framedone_handler_compat,
  1201. .unregister_framedone_handler = dss_mgr_unregister_framedone_handler_compat,
  1202. };
  1203. static int compat_refcnt;
  1204. static DEFINE_MUTEX(compat_init_lock);
  1205. int omapdss_compat_init(void)
  1206. {
  1207. struct platform_device *pdev = dss_get_core_pdev();
  1208. int i, r;
  1209. mutex_lock(&compat_init_lock);
  1210. if (compat_refcnt++ > 0)
  1211. goto out;
  1212. apply_init_priv();
  1213. dss_init_overlay_managers_sysfs(pdev);
  1214. dss_init_overlays(pdev);
  1215. for (i = 0; i < omap_dss_get_num_overlay_managers(); i++) {
  1216. struct omap_overlay_manager *mgr;
  1217. mgr = omap_dss_get_overlay_manager(i);
  1218. mgr->set_output = &dss_mgr_set_output;
  1219. mgr->unset_output = &dss_mgr_unset_output;
  1220. mgr->apply = &omap_dss_mgr_apply;
  1221. mgr->set_manager_info = &dss_mgr_set_info;
  1222. mgr->get_manager_info = &dss_mgr_get_info;
  1223. mgr->wait_for_go = &dss_mgr_wait_for_go;
  1224. mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
  1225. mgr->get_device = &dss_mgr_get_device;
  1226. }
  1227. for (i = 0; i < omap_dss_get_num_overlays(); i++) {
  1228. struct omap_overlay *ovl = omap_dss_get_overlay(i);
  1229. ovl->is_enabled = &dss_ovl_is_enabled;
  1230. ovl->enable = &dss_ovl_enable;
  1231. ovl->disable = &dss_ovl_disable;
  1232. ovl->set_manager = &dss_ovl_set_manager;
  1233. ovl->unset_manager = &dss_ovl_unset_manager;
  1234. ovl->set_overlay_info = &dss_ovl_set_info;
  1235. ovl->get_overlay_info = &dss_ovl_get_info;
  1236. ovl->wait_for_go = &dss_mgr_wait_for_go_ovl;
  1237. ovl->get_device = &dss_ovl_get_device;
  1238. }
  1239. r = dss_install_mgr_ops(&apply_mgr_ops);
  1240. if (r)
  1241. goto err_mgr_ops;
  1242. r = display_init_sysfs(pdev);
  1243. if (r)
  1244. goto err_disp_sysfs;
  1245. dispc_runtime_get();
  1246. r = dss_dispc_initialize_irq();
  1247. if (r)
  1248. goto err_init_irq;
  1249. dispc_runtime_put();
  1250. out:
  1251. mutex_unlock(&compat_init_lock);
  1252. return 0;
  1253. err_init_irq:
  1254. dispc_runtime_put();
  1255. display_uninit_sysfs(pdev);
  1256. err_disp_sysfs:
  1257. dss_uninstall_mgr_ops();
  1258. err_mgr_ops:
  1259. dss_uninit_overlay_managers_sysfs(pdev);
  1260. dss_uninit_overlays(pdev);
  1261. compat_refcnt--;
  1262. mutex_unlock(&compat_init_lock);
  1263. return r;
  1264. }
  1265. EXPORT_SYMBOL(omapdss_compat_init);
  1266. void omapdss_compat_uninit(void)
  1267. {
  1268. struct platform_device *pdev = dss_get_core_pdev();
  1269. mutex_lock(&compat_init_lock);
  1270. if (--compat_refcnt > 0)
  1271. goto out;
  1272. dss_dispc_uninitialize_irq();
  1273. display_uninit_sysfs(pdev);
  1274. dss_uninstall_mgr_ops();
  1275. dss_uninit_overlay_managers_sysfs(pdev);
  1276. dss_uninit_overlays(pdev);
  1277. out:
  1278. mutex_unlock(&compat_init_lock);
  1279. }
  1280. EXPORT_SYMBOL(omapdss_compat_uninit);