manager.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  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 <video/omapdss.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, "%#x\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. r = kstrtouint(buf, 0, &color);
  99. if (r)
  100. return r;
  101. mgr->get_manager_info(mgr, &info);
  102. info.default_color = color;
  103. r = mgr->set_manager_info(mgr, &info);
  104. if (r)
  105. return r;
  106. r = mgr->apply(mgr);
  107. if (r)
  108. return r;
  109. return size;
  110. }
  111. static const char *trans_key_type_str[] = {
  112. "gfx-destination",
  113. "video-source",
  114. };
  115. static ssize_t manager_trans_key_type_show(struct omap_overlay_manager *mgr,
  116. char *buf)
  117. {
  118. enum omap_dss_trans_key_type key_type;
  119. key_type = mgr->info.trans_key_type;
  120. BUG_ON(key_type >= ARRAY_SIZE(trans_key_type_str));
  121. return snprintf(buf, PAGE_SIZE, "%s\n", trans_key_type_str[key_type]);
  122. }
  123. static ssize_t manager_trans_key_type_store(struct omap_overlay_manager *mgr,
  124. const char *buf, size_t size)
  125. {
  126. enum omap_dss_trans_key_type key_type;
  127. struct omap_overlay_manager_info info;
  128. int r;
  129. for (key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
  130. key_type < ARRAY_SIZE(trans_key_type_str); key_type++) {
  131. if (sysfs_streq(buf, trans_key_type_str[key_type]))
  132. break;
  133. }
  134. if (key_type == ARRAY_SIZE(trans_key_type_str))
  135. return -EINVAL;
  136. mgr->get_manager_info(mgr, &info);
  137. info.trans_key_type = key_type;
  138. r = mgr->set_manager_info(mgr, &info);
  139. if (r)
  140. return r;
  141. r = mgr->apply(mgr);
  142. if (r)
  143. return r;
  144. return size;
  145. }
  146. static ssize_t manager_trans_key_value_show(struct omap_overlay_manager *mgr,
  147. char *buf)
  148. {
  149. return snprintf(buf, PAGE_SIZE, "%#x\n", mgr->info.trans_key);
  150. }
  151. static ssize_t manager_trans_key_value_store(struct omap_overlay_manager *mgr,
  152. const char *buf, size_t size)
  153. {
  154. struct omap_overlay_manager_info info;
  155. u32 key_value;
  156. int r;
  157. r = kstrtouint(buf, 0, &key_value);
  158. if (r)
  159. return r;
  160. mgr->get_manager_info(mgr, &info);
  161. info.trans_key = key_value;
  162. r = mgr->set_manager_info(mgr, &info);
  163. if (r)
  164. return r;
  165. r = mgr->apply(mgr);
  166. if (r)
  167. return r;
  168. return size;
  169. }
  170. static ssize_t manager_trans_key_enabled_show(struct omap_overlay_manager *mgr,
  171. char *buf)
  172. {
  173. return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_enabled);
  174. }
  175. static ssize_t manager_trans_key_enabled_store(struct omap_overlay_manager *mgr,
  176. const char *buf, size_t size)
  177. {
  178. struct omap_overlay_manager_info info;
  179. bool enable;
  180. int r;
  181. r = strtobool(buf, &enable);
  182. if (r)
  183. return r;
  184. mgr->get_manager_info(mgr, &info);
  185. info.trans_enabled = enable;
  186. r = mgr->set_manager_info(mgr, &info);
  187. if (r)
  188. return r;
  189. r = mgr->apply(mgr);
  190. if (r)
  191. return r;
  192. return size;
  193. }
  194. static ssize_t manager_alpha_blending_enabled_show(
  195. struct omap_overlay_manager *mgr, char *buf)
  196. {
  197. WARN_ON(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER));
  198. return snprintf(buf, PAGE_SIZE, "%d\n",
  199. mgr->info.partial_alpha_enabled);
  200. }
  201. static ssize_t manager_alpha_blending_enabled_store(
  202. struct omap_overlay_manager *mgr,
  203. const char *buf, size_t size)
  204. {
  205. struct omap_overlay_manager_info info;
  206. bool enable;
  207. int r;
  208. WARN_ON(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER));
  209. r = strtobool(buf, &enable);
  210. if (r)
  211. return r;
  212. mgr->get_manager_info(mgr, &info);
  213. info.partial_alpha_enabled = enable;
  214. r = mgr->set_manager_info(mgr, &info);
  215. if (r)
  216. return r;
  217. r = mgr->apply(mgr);
  218. if (r)
  219. return r;
  220. return size;
  221. }
  222. static ssize_t manager_cpr_enable_show(struct omap_overlay_manager *mgr,
  223. char *buf)
  224. {
  225. return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.cpr_enable);
  226. }
  227. static ssize_t manager_cpr_enable_store(struct omap_overlay_manager *mgr,
  228. const char *buf, size_t size)
  229. {
  230. struct omap_overlay_manager_info info;
  231. int r;
  232. bool enable;
  233. if (!dss_has_feature(FEAT_CPR))
  234. return -ENODEV;
  235. r = strtobool(buf, &enable);
  236. if (r)
  237. return r;
  238. mgr->get_manager_info(mgr, &info);
  239. if (info.cpr_enable == enable)
  240. return size;
  241. info.cpr_enable = enable;
  242. r = mgr->set_manager_info(mgr, &info);
  243. if (r)
  244. return r;
  245. r = mgr->apply(mgr);
  246. if (r)
  247. return r;
  248. return size;
  249. }
  250. static ssize_t manager_cpr_coef_show(struct omap_overlay_manager *mgr,
  251. char *buf)
  252. {
  253. struct omap_overlay_manager_info info;
  254. mgr->get_manager_info(mgr, &info);
  255. return snprintf(buf, PAGE_SIZE,
  256. "%d %d %d %d %d %d %d %d %d\n",
  257. info.cpr_coefs.rr,
  258. info.cpr_coefs.rg,
  259. info.cpr_coefs.rb,
  260. info.cpr_coefs.gr,
  261. info.cpr_coefs.gg,
  262. info.cpr_coefs.gb,
  263. info.cpr_coefs.br,
  264. info.cpr_coefs.bg,
  265. info.cpr_coefs.bb);
  266. }
  267. static ssize_t manager_cpr_coef_store(struct omap_overlay_manager *mgr,
  268. const char *buf, size_t size)
  269. {
  270. struct omap_overlay_manager_info info;
  271. struct omap_dss_cpr_coefs coefs;
  272. int r, i;
  273. s16 *arr;
  274. if (!dss_has_feature(FEAT_CPR))
  275. return -ENODEV;
  276. if (sscanf(buf, "%hd %hd %hd %hd %hd %hd %hd %hd %hd",
  277. &coefs.rr, &coefs.rg, &coefs.rb,
  278. &coefs.gr, &coefs.gg, &coefs.gb,
  279. &coefs.br, &coefs.bg, &coefs.bb) != 9)
  280. return -EINVAL;
  281. arr = (s16[]){ coefs.rr, coefs.rg, coefs.rb,
  282. coefs.gr, coefs.gg, coefs.gb,
  283. coefs.br, coefs.bg, coefs.bb };
  284. for (i = 0; i < 9; ++i) {
  285. if (arr[i] < -512 || arr[i] > 511)
  286. return -EINVAL;
  287. }
  288. mgr->get_manager_info(mgr, &info);
  289. info.cpr_coefs = coefs;
  290. r = mgr->set_manager_info(mgr, &info);
  291. if (r)
  292. return r;
  293. r = mgr->apply(mgr);
  294. if (r)
  295. return r;
  296. return size;
  297. }
  298. struct manager_attribute {
  299. struct attribute attr;
  300. ssize_t (*show)(struct omap_overlay_manager *, char *);
  301. ssize_t (*store)(struct omap_overlay_manager *, const char *, size_t);
  302. };
  303. #define MANAGER_ATTR(_name, _mode, _show, _store) \
  304. struct manager_attribute manager_attr_##_name = \
  305. __ATTR(_name, _mode, _show, _store)
  306. static MANAGER_ATTR(name, S_IRUGO, manager_name_show, NULL);
  307. static MANAGER_ATTR(display, S_IRUGO|S_IWUSR,
  308. manager_display_show, manager_display_store);
  309. static MANAGER_ATTR(default_color, S_IRUGO|S_IWUSR,
  310. manager_default_color_show, manager_default_color_store);
  311. static MANAGER_ATTR(trans_key_type, S_IRUGO|S_IWUSR,
  312. manager_trans_key_type_show, manager_trans_key_type_store);
  313. static MANAGER_ATTR(trans_key_value, S_IRUGO|S_IWUSR,
  314. manager_trans_key_value_show, manager_trans_key_value_store);
  315. static MANAGER_ATTR(trans_key_enabled, S_IRUGO|S_IWUSR,
  316. manager_trans_key_enabled_show,
  317. manager_trans_key_enabled_store);
  318. static MANAGER_ATTR(alpha_blending_enabled, S_IRUGO|S_IWUSR,
  319. manager_alpha_blending_enabled_show,
  320. manager_alpha_blending_enabled_store);
  321. static MANAGER_ATTR(cpr_enable, S_IRUGO|S_IWUSR,
  322. manager_cpr_enable_show,
  323. manager_cpr_enable_store);
  324. static MANAGER_ATTR(cpr_coef, S_IRUGO|S_IWUSR,
  325. manager_cpr_coef_show,
  326. manager_cpr_coef_store);
  327. static struct attribute *manager_sysfs_attrs[] = {
  328. &manager_attr_name.attr,
  329. &manager_attr_display.attr,
  330. &manager_attr_default_color.attr,
  331. &manager_attr_trans_key_type.attr,
  332. &manager_attr_trans_key_value.attr,
  333. &manager_attr_trans_key_enabled.attr,
  334. &manager_attr_alpha_blending_enabled.attr,
  335. &manager_attr_cpr_enable.attr,
  336. &manager_attr_cpr_coef.attr,
  337. NULL
  338. };
  339. static ssize_t manager_attr_show(struct kobject *kobj, struct attribute *attr,
  340. char *buf)
  341. {
  342. struct omap_overlay_manager *manager;
  343. struct manager_attribute *manager_attr;
  344. manager = container_of(kobj, struct omap_overlay_manager, kobj);
  345. manager_attr = container_of(attr, struct manager_attribute, attr);
  346. if (!manager_attr->show)
  347. return -ENOENT;
  348. return manager_attr->show(manager, buf);
  349. }
  350. static ssize_t manager_attr_store(struct kobject *kobj, struct attribute *attr,
  351. const char *buf, size_t size)
  352. {
  353. struct omap_overlay_manager *manager;
  354. struct manager_attribute *manager_attr;
  355. manager = container_of(kobj, struct omap_overlay_manager, kobj);
  356. manager_attr = container_of(attr, struct manager_attribute, attr);
  357. if (!manager_attr->store)
  358. return -ENOENT;
  359. return manager_attr->store(manager, buf, size);
  360. }
  361. static const struct sysfs_ops manager_sysfs_ops = {
  362. .show = manager_attr_show,
  363. .store = manager_attr_store,
  364. };
  365. static struct kobj_type manager_ktype = {
  366. .sysfs_ops = &manager_sysfs_ops,
  367. .default_attrs = manager_sysfs_attrs,
  368. };
  369. /*
  370. * We have 4 levels of cache for the dispc settings. First two are in SW and
  371. * the latter two in HW.
  372. *
  373. * +--------------------+
  374. * |overlay/manager_info|
  375. * +--------------------+
  376. * v
  377. * apply()
  378. * v
  379. * +--------------------+
  380. * | dss_cache |
  381. * +--------------------+
  382. * v
  383. * configure()
  384. * v
  385. * +--------------------+
  386. * | shadow registers |
  387. * +--------------------+
  388. * v
  389. * VFP or lcd/digit_enable
  390. * v
  391. * +--------------------+
  392. * | registers |
  393. * +--------------------+
  394. */
  395. struct overlay_cache_data {
  396. /* If true, cache changed, but not written to shadow registers. Set
  397. * in apply(), cleared when registers written. */
  398. bool dirty;
  399. /* If true, shadow registers contain changed values not yet in real
  400. * registers. Set when writing to shadow registers, cleared at
  401. * VSYNC/EVSYNC */
  402. bool shadow_dirty;
  403. bool enabled;
  404. struct omap_overlay_info info;
  405. enum omap_channel channel;
  406. u32 fifo_low;
  407. u32 fifo_high;
  408. };
  409. struct manager_cache_data {
  410. /* If true, cache changed, but not written to shadow registers. Set
  411. * in apply(), cleared when registers written. */
  412. bool dirty;
  413. /* If true, shadow registers contain changed values not yet in real
  414. * registers. Set when writing to shadow registers, cleared at
  415. * VSYNC/EVSYNC */
  416. bool shadow_dirty;
  417. struct omap_overlay_manager_info info;
  418. bool manual_update;
  419. bool do_manual_update;
  420. };
  421. static struct {
  422. spinlock_t lock;
  423. struct overlay_cache_data overlay_cache[MAX_DSS_OVERLAYS];
  424. struct manager_cache_data manager_cache[MAX_DSS_MANAGERS];
  425. bool irq_enabled;
  426. } dss_cache;
  427. static bool ovl_manual_update(struct omap_overlay *ovl)
  428. {
  429. return ovl->manager->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
  430. }
  431. static bool mgr_manual_update(struct omap_overlay_manager *mgr)
  432. {
  433. return mgr->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
  434. }
  435. static int omap_dss_set_device(struct omap_overlay_manager *mgr,
  436. struct omap_dss_device *dssdev)
  437. {
  438. int i;
  439. int r;
  440. if (dssdev->manager) {
  441. DSSERR("display '%s' already has a manager '%s'\n",
  442. dssdev->name, dssdev->manager->name);
  443. return -EINVAL;
  444. }
  445. if ((mgr->supported_displays & dssdev->type) == 0) {
  446. DSSERR("display '%s' does not support manager '%s'\n",
  447. dssdev->name, mgr->name);
  448. return -EINVAL;
  449. }
  450. for (i = 0; i < mgr->num_overlays; i++) {
  451. struct omap_overlay *ovl = mgr->overlays[i];
  452. if (ovl->manager != mgr || !ovl->info.enabled)
  453. continue;
  454. r = dss_check_overlay(ovl, dssdev);
  455. if (r)
  456. return r;
  457. }
  458. dssdev->manager = mgr;
  459. mgr->device = dssdev;
  460. mgr->device_changed = true;
  461. return 0;
  462. }
  463. static int omap_dss_unset_device(struct omap_overlay_manager *mgr)
  464. {
  465. if (!mgr->device) {
  466. DSSERR("failed to unset display, display not set.\n");
  467. return -EINVAL;
  468. }
  469. /*
  470. * Don't allow currently enabled displays to have the overlay manager
  471. * pulled out from underneath them
  472. */
  473. if (mgr->device->state != OMAP_DSS_DISPLAY_DISABLED)
  474. return -EINVAL;
  475. mgr->device->manager = NULL;
  476. mgr->device = NULL;
  477. mgr->device_changed = true;
  478. return 0;
  479. }
  480. static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
  481. {
  482. unsigned long timeout = msecs_to_jiffies(500);
  483. u32 irq;
  484. if (mgr->device->type == OMAP_DISPLAY_TYPE_VENC) {
  485. irq = DISPC_IRQ_EVSYNC_ODD;
  486. } else if (mgr->device->type == OMAP_DISPLAY_TYPE_HDMI) {
  487. irq = DISPC_IRQ_EVSYNC_EVEN;
  488. } else {
  489. if (mgr->id == OMAP_DSS_CHANNEL_LCD)
  490. irq = DISPC_IRQ_VSYNC;
  491. else
  492. irq = DISPC_IRQ_VSYNC2;
  493. }
  494. return omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
  495. }
  496. static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
  497. {
  498. unsigned long timeout = msecs_to_jiffies(500);
  499. struct manager_cache_data *mc;
  500. u32 irq;
  501. int r;
  502. int i;
  503. struct omap_dss_device *dssdev = mgr->device;
  504. if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  505. return 0;
  506. if (mgr_manual_update(mgr))
  507. return 0;
  508. if (dssdev->type == OMAP_DISPLAY_TYPE_VENC
  509. || dssdev->type == OMAP_DISPLAY_TYPE_HDMI) {
  510. irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
  511. } else {
  512. irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
  513. DISPC_IRQ_VSYNC : DISPC_IRQ_VSYNC2;
  514. }
  515. mc = &dss_cache.manager_cache[mgr->id];
  516. i = 0;
  517. while (1) {
  518. unsigned long flags;
  519. bool shadow_dirty, dirty;
  520. spin_lock_irqsave(&dss_cache.lock, flags);
  521. dirty = mc->dirty;
  522. shadow_dirty = mc->shadow_dirty;
  523. spin_unlock_irqrestore(&dss_cache.lock, flags);
  524. if (!dirty && !shadow_dirty) {
  525. r = 0;
  526. break;
  527. }
  528. /* 4 iterations is the worst case:
  529. * 1 - initial iteration, dirty = true (between VFP and VSYNC)
  530. * 2 - first VSYNC, dirty = true
  531. * 3 - dirty = false, shadow_dirty = true
  532. * 4 - shadow_dirty = false */
  533. if (i++ == 3) {
  534. DSSERR("mgr(%d)->wait_for_go() not finishing\n",
  535. mgr->id);
  536. r = 0;
  537. break;
  538. }
  539. r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
  540. if (r == -ERESTARTSYS)
  541. break;
  542. if (r) {
  543. DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
  544. break;
  545. }
  546. }
  547. return r;
  548. }
  549. int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
  550. {
  551. unsigned long timeout = msecs_to_jiffies(500);
  552. struct overlay_cache_data *oc;
  553. struct omap_dss_device *dssdev;
  554. u32 irq;
  555. int r;
  556. int i;
  557. if (!ovl->manager)
  558. return 0;
  559. dssdev = ovl->manager->device;
  560. if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  561. return 0;
  562. if (ovl_manual_update(ovl))
  563. return 0;
  564. if (dssdev->type == OMAP_DISPLAY_TYPE_VENC
  565. || dssdev->type == OMAP_DISPLAY_TYPE_HDMI) {
  566. irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
  567. } else {
  568. irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
  569. DISPC_IRQ_VSYNC : DISPC_IRQ_VSYNC2;
  570. }
  571. oc = &dss_cache.overlay_cache[ovl->id];
  572. i = 0;
  573. while (1) {
  574. unsigned long flags;
  575. bool shadow_dirty, dirty;
  576. spin_lock_irqsave(&dss_cache.lock, flags);
  577. dirty = oc->dirty;
  578. shadow_dirty = oc->shadow_dirty;
  579. spin_unlock_irqrestore(&dss_cache.lock, flags);
  580. if (!dirty && !shadow_dirty) {
  581. r = 0;
  582. break;
  583. }
  584. /* 4 iterations is the worst case:
  585. * 1 - initial iteration, dirty = true (between VFP and VSYNC)
  586. * 2 - first VSYNC, dirty = true
  587. * 3 - dirty = false, shadow_dirty = true
  588. * 4 - shadow_dirty = false */
  589. if (i++ == 3) {
  590. DSSERR("ovl(%d)->wait_for_go() not finishing\n",
  591. ovl->id);
  592. r = 0;
  593. break;
  594. }
  595. r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
  596. if (r == -ERESTARTSYS)
  597. break;
  598. if (r) {
  599. DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
  600. break;
  601. }
  602. }
  603. return r;
  604. }
  605. static int overlay_enabled(struct omap_overlay *ovl)
  606. {
  607. return ovl->info.enabled && ovl->manager && ovl->manager->device;
  608. }
  609. static int configure_overlay(enum omap_plane plane)
  610. {
  611. struct omap_overlay *ovl;
  612. struct overlay_cache_data *c;
  613. struct omap_overlay_info *oi;
  614. bool ilace, replication;
  615. int r;
  616. DSSDBGF("%d", plane);
  617. c = &dss_cache.overlay_cache[plane];
  618. oi = &c->info;
  619. if (!c->enabled) {
  620. dispc_ovl_enable(plane, 0);
  621. return 0;
  622. }
  623. ovl = omap_dss_get_overlay(plane);
  624. replication = dss_use_replication(ovl->manager->device, oi->color_mode);
  625. ilace = ovl->manager->device->type == OMAP_DISPLAY_TYPE_VENC;
  626. dispc_ovl_set_channel_out(plane, c->channel);
  627. r = dispc_ovl_setup(plane, oi, ilace, replication);
  628. if (r) {
  629. /* this shouldn't happen */
  630. DSSERR("dispc_ovl_setup failed for ovl %d\n", plane);
  631. dispc_ovl_enable(plane, 0);
  632. return r;
  633. }
  634. dispc_ovl_set_fifo_threshold(plane, c->fifo_low, c->fifo_high);
  635. dispc_ovl_enable(plane, 1);
  636. return 0;
  637. }
  638. static void configure_manager(enum omap_channel channel)
  639. {
  640. struct omap_overlay_manager_info *mi;
  641. DSSDBGF("%d", channel);
  642. /* picking info from the cache */
  643. mi = &dss_cache.manager_cache[channel].info;
  644. dispc_mgr_setup(channel, mi);
  645. }
  646. /* configure_dispc() tries to write values from cache to shadow registers.
  647. * It writes only to those managers/overlays that are not busy.
  648. * returns 0 if everything could be written to shadow registers.
  649. * returns 1 if not everything could be written to shadow registers. */
  650. static int configure_dispc(void)
  651. {
  652. struct overlay_cache_data *oc;
  653. struct manager_cache_data *mc;
  654. const int num_ovls = dss_feat_get_num_ovls();
  655. const int num_mgrs = dss_feat_get_num_mgrs();
  656. int i;
  657. int r;
  658. bool mgr_busy[MAX_DSS_MANAGERS];
  659. bool mgr_go[MAX_DSS_MANAGERS];
  660. bool busy;
  661. r = 0;
  662. busy = false;
  663. for (i = 0; i < num_mgrs; i++) {
  664. mgr_busy[i] = dispc_mgr_go_busy(i);
  665. mgr_go[i] = false;
  666. }
  667. /* Commit overlay settings */
  668. for (i = 0; i < num_ovls; ++i) {
  669. oc = &dss_cache.overlay_cache[i];
  670. mc = &dss_cache.manager_cache[oc->channel];
  671. if (!oc->dirty)
  672. continue;
  673. if (mc->manual_update && !mc->do_manual_update)
  674. continue;
  675. if (mgr_busy[oc->channel]) {
  676. busy = true;
  677. continue;
  678. }
  679. r = configure_overlay(i);
  680. if (r)
  681. DSSERR("configure_overlay %d failed\n", i);
  682. oc->dirty = false;
  683. oc->shadow_dirty = true;
  684. mgr_go[oc->channel] = true;
  685. }
  686. /* Commit manager settings */
  687. for (i = 0; i < num_mgrs; ++i) {
  688. mc = &dss_cache.manager_cache[i];
  689. if (!mc->dirty)
  690. continue;
  691. if (mc->manual_update && !mc->do_manual_update)
  692. continue;
  693. if (mgr_busy[i]) {
  694. busy = true;
  695. continue;
  696. }
  697. configure_manager(i);
  698. mc->dirty = false;
  699. mc->shadow_dirty = true;
  700. mgr_go[i] = true;
  701. }
  702. /* set GO */
  703. for (i = 0; i < num_mgrs; ++i) {
  704. mc = &dss_cache.manager_cache[i];
  705. if (!mgr_go[i])
  706. continue;
  707. /* We don't need GO with manual update display. LCD iface will
  708. * always be turned off after frame, and new settings will be
  709. * taken in to use at next update */
  710. if (!mc->manual_update)
  711. dispc_mgr_go(i);
  712. }
  713. if (busy)
  714. r = 1;
  715. else
  716. r = 0;
  717. return r;
  718. }
  719. void dss_mgr_start_update(struct omap_overlay_manager *mgr)
  720. {
  721. struct manager_cache_data *mc;
  722. struct overlay_cache_data *oc;
  723. const int num_ovls = dss_feat_get_num_ovls();
  724. const int num_mgrs = dss_feat_get_num_mgrs();
  725. int i;
  726. mc = &dss_cache.manager_cache[mgr->id];
  727. mc->do_manual_update = true;
  728. configure_dispc();
  729. mc->do_manual_update = false;
  730. for (i = 0; i < num_ovls; ++i) {
  731. oc = &dss_cache.overlay_cache[i];
  732. if (oc->channel != mgr->id)
  733. continue;
  734. oc->shadow_dirty = false;
  735. }
  736. for (i = 0; i < num_mgrs; ++i) {
  737. mc = &dss_cache.manager_cache[i];
  738. if (mgr->id != i)
  739. continue;
  740. mc->shadow_dirty = false;
  741. }
  742. mgr->enable(mgr);
  743. }
  744. static void dss_apply_irq_handler(void *data, u32 mask)
  745. {
  746. struct manager_cache_data *mc;
  747. struct overlay_cache_data *oc;
  748. const int num_ovls = dss_feat_get_num_ovls();
  749. const int num_mgrs = dss_feat_get_num_mgrs();
  750. int i, r;
  751. bool mgr_busy[MAX_DSS_MANAGERS];
  752. u32 irq_mask;
  753. for (i = 0; i < num_mgrs; i++)
  754. mgr_busy[i] = dispc_mgr_go_busy(i);
  755. spin_lock(&dss_cache.lock);
  756. for (i = 0; i < num_ovls; ++i) {
  757. oc = &dss_cache.overlay_cache[i];
  758. if (!mgr_busy[oc->channel])
  759. oc->shadow_dirty = false;
  760. }
  761. for (i = 0; i < num_mgrs; ++i) {
  762. mc = &dss_cache.manager_cache[i];
  763. if (!mgr_busy[i])
  764. mc->shadow_dirty = false;
  765. }
  766. r = configure_dispc();
  767. if (r == 1)
  768. goto end;
  769. /* re-read busy flags */
  770. for (i = 0; i < num_mgrs; i++)
  771. mgr_busy[i] = dispc_mgr_go_busy(i);
  772. /* keep running as long as there are busy managers, so that
  773. * we can collect overlay-applied information */
  774. for (i = 0; i < num_mgrs; ++i) {
  775. if (mgr_busy[i])
  776. goto end;
  777. }
  778. irq_mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
  779. DISPC_IRQ_EVSYNC_EVEN;
  780. if (dss_has_feature(FEAT_MGR_LCD2))
  781. irq_mask |= DISPC_IRQ_VSYNC2;
  782. omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, irq_mask);
  783. dss_cache.irq_enabled = false;
  784. end:
  785. spin_unlock(&dss_cache.lock);
  786. }
  787. static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
  788. {
  789. struct overlay_cache_data *oc;
  790. struct manager_cache_data *mc;
  791. int i;
  792. struct omap_overlay *ovl;
  793. unsigned long flags;
  794. int r;
  795. DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
  796. r = dispc_runtime_get();
  797. if (r)
  798. return r;
  799. spin_lock_irqsave(&dss_cache.lock, flags);
  800. /* Configure overlays */
  801. for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
  802. struct omap_dss_device *dssdev;
  803. ovl = omap_dss_get_overlay(i);
  804. oc = &dss_cache.overlay_cache[ovl->id];
  805. if (ovl->manager_changed) {
  806. ovl->manager_changed = false;
  807. ovl->info_dirty = true;
  808. }
  809. if (!overlay_enabled(ovl)) {
  810. if (oc->enabled) {
  811. oc->enabled = false;
  812. oc->dirty = true;
  813. }
  814. continue;
  815. }
  816. if (!ovl->info_dirty)
  817. continue;
  818. dssdev = ovl->manager->device;
  819. if (dss_check_overlay(ovl, dssdev)) {
  820. if (oc->enabled) {
  821. oc->enabled = false;
  822. oc->dirty = true;
  823. }
  824. continue;
  825. }
  826. ovl->info_dirty = false;
  827. oc->dirty = true;
  828. oc->info = ovl->info;
  829. oc->channel = ovl->manager->id;
  830. oc->enabled = true;
  831. }
  832. /* Configure managers */
  833. list_for_each_entry(mgr, &manager_list, list) {
  834. mc = &dss_cache.manager_cache[mgr->id];
  835. if (mgr->device_changed) {
  836. mgr->device_changed = false;
  837. mgr->info_dirty = true;
  838. }
  839. if (!mgr->info_dirty)
  840. continue;
  841. if (!mgr->device)
  842. continue;
  843. mgr->info_dirty = false;
  844. mc->dirty = true;
  845. mc->info = mgr->info;
  846. mc->manual_update = mgr_manual_update(mgr);
  847. }
  848. /* Configure overlay fifos */
  849. for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
  850. struct omap_dss_device *dssdev;
  851. u32 size, burst_size;
  852. ovl = omap_dss_get_overlay(i);
  853. oc = &dss_cache.overlay_cache[ovl->id];
  854. if (!oc->enabled)
  855. continue;
  856. dssdev = ovl->manager->device;
  857. size = dispc_ovl_get_fifo_size(ovl->id);
  858. burst_size = dispc_ovl_get_burst_size(ovl->id);
  859. switch (dssdev->type) {
  860. case OMAP_DISPLAY_TYPE_DPI:
  861. case OMAP_DISPLAY_TYPE_DBI:
  862. case OMAP_DISPLAY_TYPE_SDI:
  863. case OMAP_DISPLAY_TYPE_VENC:
  864. case OMAP_DISPLAY_TYPE_HDMI:
  865. default_get_overlay_fifo_thresholds(ovl->id, size,
  866. burst_size, &oc->fifo_low,
  867. &oc->fifo_high);
  868. break;
  869. #ifdef CONFIG_OMAP2_DSS_DSI
  870. case OMAP_DISPLAY_TYPE_DSI:
  871. dsi_get_overlay_fifo_thresholds(ovl->id, size,
  872. burst_size, &oc->fifo_low,
  873. &oc->fifo_high);
  874. break;
  875. #endif
  876. default:
  877. BUG();
  878. }
  879. }
  880. r = 0;
  881. if (!dss_cache.irq_enabled) {
  882. u32 mask;
  883. mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
  884. DISPC_IRQ_EVSYNC_EVEN;
  885. if (dss_has_feature(FEAT_MGR_LCD2))
  886. mask |= DISPC_IRQ_VSYNC2;
  887. r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
  888. dss_cache.irq_enabled = true;
  889. }
  890. configure_dispc();
  891. spin_unlock_irqrestore(&dss_cache.lock, flags);
  892. dispc_runtime_put();
  893. return r;
  894. }
  895. static int dss_check_manager(struct omap_overlay_manager *mgr)
  896. {
  897. if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
  898. /*
  899. * OMAP3 supports only graphics source transparency color key
  900. * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
  901. * Alpha Mode
  902. */
  903. if (mgr->info.partial_alpha_enabled && mgr->info.trans_enabled
  904. && mgr->info.trans_key_type !=
  905. OMAP_DSS_COLOR_KEY_GFX_DST)
  906. return -EINVAL;
  907. }
  908. return 0;
  909. }
  910. static int omap_dss_mgr_set_info(struct omap_overlay_manager *mgr,
  911. struct omap_overlay_manager_info *info)
  912. {
  913. int r;
  914. struct omap_overlay_manager_info old_info;
  915. old_info = mgr->info;
  916. mgr->info = *info;
  917. r = dss_check_manager(mgr);
  918. if (r) {
  919. mgr->info = old_info;
  920. return r;
  921. }
  922. mgr->info_dirty = true;
  923. return 0;
  924. }
  925. static void omap_dss_mgr_get_info(struct omap_overlay_manager *mgr,
  926. struct omap_overlay_manager_info *info)
  927. {
  928. *info = mgr->info;
  929. }
  930. static int dss_mgr_enable(struct omap_overlay_manager *mgr)
  931. {
  932. dispc_mgr_enable(mgr->id, 1);
  933. return 0;
  934. }
  935. static int dss_mgr_disable(struct omap_overlay_manager *mgr)
  936. {
  937. dispc_mgr_enable(mgr->id, 0);
  938. return 0;
  939. }
  940. static void omap_dss_add_overlay_manager(struct omap_overlay_manager *manager)
  941. {
  942. ++num_managers;
  943. list_add_tail(&manager->list, &manager_list);
  944. }
  945. int dss_init_overlay_managers(struct platform_device *pdev)
  946. {
  947. int i, r;
  948. spin_lock_init(&dss_cache.lock);
  949. INIT_LIST_HEAD(&manager_list);
  950. num_managers = 0;
  951. for (i = 0; i < dss_feat_get_num_mgrs(); ++i) {
  952. struct omap_overlay_manager *mgr;
  953. mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
  954. BUG_ON(mgr == NULL);
  955. switch (i) {
  956. case 0:
  957. mgr->name = "lcd";
  958. mgr->id = OMAP_DSS_CHANNEL_LCD;
  959. break;
  960. case 1:
  961. mgr->name = "tv";
  962. mgr->id = OMAP_DSS_CHANNEL_DIGIT;
  963. break;
  964. case 2:
  965. mgr->name = "lcd2";
  966. mgr->id = OMAP_DSS_CHANNEL_LCD2;
  967. break;
  968. }
  969. mgr->set_device = &omap_dss_set_device;
  970. mgr->unset_device = &omap_dss_unset_device;
  971. mgr->apply = &omap_dss_mgr_apply;
  972. mgr->set_manager_info = &omap_dss_mgr_set_info;
  973. mgr->get_manager_info = &omap_dss_mgr_get_info;
  974. mgr->wait_for_go = &dss_mgr_wait_for_go;
  975. mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
  976. mgr->enable = &dss_mgr_enable;
  977. mgr->disable = &dss_mgr_disable;
  978. mgr->caps = 0;
  979. mgr->supported_displays =
  980. dss_feat_get_supported_displays(mgr->id);
  981. dss_overlay_setup_dispc_manager(mgr);
  982. omap_dss_add_overlay_manager(mgr);
  983. r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
  984. &pdev->dev.kobj, "manager%d", i);
  985. if (r) {
  986. DSSERR("failed to create sysfs file\n");
  987. continue;
  988. }
  989. }
  990. return 0;
  991. }
  992. void dss_uninit_overlay_managers(struct platform_device *pdev)
  993. {
  994. struct omap_overlay_manager *mgr;
  995. while (!list_empty(&manager_list)) {
  996. mgr = list_first_entry(&manager_list,
  997. struct omap_overlay_manager, list);
  998. list_del(&mgr->list);
  999. kobject_del(&mgr->kobj);
  1000. kobject_put(&mgr->kobj);
  1001. kfree(mgr);
  1002. }
  1003. num_managers = 0;
  1004. }
  1005. int omap_dss_get_num_overlay_managers(void)
  1006. {
  1007. return num_managers;
  1008. }
  1009. EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
  1010. struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
  1011. {
  1012. int i = 0;
  1013. struct omap_overlay_manager *mgr;
  1014. list_for_each_entry(mgr, &manager_list, list) {
  1015. if (i++ == num)
  1016. return mgr;
  1017. }
  1018. return NULL;
  1019. }
  1020. EXPORT_SYMBOL(omap_dss_get_overlay_manager);