manager.c 35 KB

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