manager.c 34 KB

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