display.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /*
  2. * linux/drivers/video/omap2/dss/display.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 "DISPLAY"
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/jiffies.h>
  26. #include <linux/list.h>
  27. #include <linux/platform_device.h>
  28. #include <plat/display.h>
  29. #include "dss.h"
  30. static LIST_HEAD(display_list);
  31. static ssize_t display_enabled_show(struct device *dev,
  32. struct device_attribute *attr, char *buf)
  33. {
  34. struct omap_dss_device *dssdev = to_dss_device(dev);
  35. bool enabled = dssdev->state != OMAP_DSS_DISPLAY_DISABLED;
  36. return snprintf(buf, PAGE_SIZE, "%d\n", enabled);
  37. }
  38. static ssize_t display_enabled_store(struct device *dev,
  39. struct device_attribute *attr,
  40. const char *buf, size_t size)
  41. {
  42. struct omap_dss_device *dssdev = to_dss_device(dev);
  43. bool enabled, r;
  44. enabled = simple_strtoul(buf, NULL, 10);
  45. if (enabled != (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)) {
  46. if (enabled) {
  47. r = dssdev->enable(dssdev);
  48. if (r)
  49. return r;
  50. } else {
  51. dssdev->disable(dssdev);
  52. }
  53. }
  54. return size;
  55. }
  56. static ssize_t display_upd_mode_show(struct device *dev,
  57. struct device_attribute *attr, char *buf)
  58. {
  59. struct omap_dss_device *dssdev = to_dss_device(dev);
  60. enum omap_dss_update_mode mode = OMAP_DSS_UPDATE_AUTO;
  61. if (dssdev->get_update_mode)
  62. mode = dssdev->get_update_mode(dssdev);
  63. return snprintf(buf, PAGE_SIZE, "%d\n", mode);
  64. }
  65. static ssize_t display_upd_mode_store(struct device *dev,
  66. struct device_attribute *attr,
  67. const char *buf, size_t size)
  68. {
  69. struct omap_dss_device *dssdev = to_dss_device(dev);
  70. int val, r;
  71. enum omap_dss_update_mode mode;
  72. val = simple_strtoul(buf, NULL, 10);
  73. switch (val) {
  74. case OMAP_DSS_UPDATE_DISABLED:
  75. case OMAP_DSS_UPDATE_AUTO:
  76. case OMAP_DSS_UPDATE_MANUAL:
  77. mode = (enum omap_dss_update_mode)val;
  78. break;
  79. default:
  80. return -EINVAL;
  81. }
  82. r = dssdev->set_update_mode(dssdev, mode);
  83. if (r)
  84. return r;
  85. return size;
  86. }
  87. static ssize_t display_tear_show(struct device *dev,
  88. struct device_attribute *attr, char *buf)
  89. {
  90. struct omap_dss_device *dssdev = to_dss_device(dev);
  91. return snprintf(buf, PAGE_SIZE, "%d\n",
  92. dssdev->get_te ? dssdev->get_te(dssdev) : 0);
  93. }
  94. static ssize_t display_tear_store(struct device *dev,
  95. struct device_attribute *attr, const char *buf, size_t size)
  96. {
  97. struct omap_dss_device *dssdev = to_dss_device(dev);
  98. unsigned long te;
  99. int r;
  100. if (!dssdev->enable_te || !dssdev->get_te)
  101. return -ENOENT;
  102. te = simple_strtoul(buf, NULL, 0);
  103. r = dssdev->enable_te(dssdev, te);
  104. if (r)
  105. return r;
  106. return size;
  107. }
  108. static ssize_t display_timings_show(struct device *dev,
  109. struct device_attribute *attr, char *buf)
  110. {
  111. struct omap_dss_device *dssdev = to_dss_device(dev);
  112. struct omap_video_timings t;
  113. if (!dssdev->get_timings)
  114. return -ENOENT;
  115. dssdev->get_timings(dssdev, &t);
  116. return snprintf(buf, PAGE_SIZE, "%u,%u/%u/%u/%u,%u/%u/%u/%u\n",
  117. t.pixel_clock,
  118. t.x_res, t.hfp, t.hbp, t.hsw,
  119. t.y_res, t.vfp, t.vbp, t.vsw);
  120. }
  121. static ssize_t display_timings_store(struct device *dev,
  122. struct device_attribute *attr, const char *buf, size_t size)
  123. {
  124. struct omap_dss_device *dssdev = to_dss_device(dev);
  125. struct omap_video_timings t;
  126. int r, found;
  127. if (!dssdev->set_timings || !dssdev->check_timings)
  128. return -ENOENT;
  129. found = 0;
  130. #ifdef CONFIG_OMAP2_DSS_VENC
  131. if (strncmp("pal", buf, 3) == 0) {
  132. t = omap_dss_pal_timings;
  133. found = 1;
  134. } else if (strncmp("ntsc", buf, 4) == 0) {
  135. t = omap_dss_ntsc_timings;
  136. found = 1;
  137. }
  138. #endif
  139. if (!found && sscanf(buf, "%u,%hu/%hu/%hu/%hu,%hu/%hu/%hu/%hu",
  140. &t.pixel_clock,
  141. &t.x_res, &t.hfp, &t.hbp, &t.hsw,
  142. &t.y_res, &t.vfp, &t.vbp, &t.vsw) != 9)
  143. return -EINVAL;
  144. r = dssdev->check_timings(dssdev, &t);
  145. if (r)
  146. return r;
  147. dssdev->set_timings(dssdev, &t);
  148. return size;
  149. }
  150. static ssize_t display_rotate_show(struct device *dev,
  151. struct device_attribute *attr, char *buf)
  152. {
  153. struct omap_dss_device *dssdev = to_dss_device(dev);
  154. int rotate;
  155. if (!dssdev->get_rotate)
  156. return -ENOENT;
  157. rotate = dssdev->get_rotate(dssdev);
  158. return snprintf(buf, PAGE_SIZE, "%u\n", rotate);
  159. }
  160. static ssize_t display_rotate_store(struct device *dev,
  161. struct device_attribute *attr, const char *buf, size_t size)
  162. {
  163. struct omap_dss_device *dssdev = to_dss_device(dev);
  164. unsigned long rot;
  165. int r;
  166. if (!dssdev->set_rotate || !dssdev->get_rotate)
  167. return -ENOENT;
  168. rot = simple_strtoul(buf, NULL, 0);
  169. r = dssdev->set_rotate(dssdev, rot);
  170. if (r)
  171. return r;
  172. return size;
  173. }
  174. static ssize_t display_mirror_show(struct device *dev,
  175. struct device_attribute *attr, char *buf)
  176. {
  177. struct omap_dss_device *dssdev = to_dss_device(dev);
  178. int mirror;
  179. if (!dssdev->get_mirror)
  180. return -ENOENT;
  181. mirror = dssdev->get_mirror(dssdev);
  182. return snprintf(buf, PAGE_SIZE, "%u\n", mirror);
  183. }
  184. static ssize_t display_mirror_store(struct device *dev,
  185. struct device_attribute *attr, const char *buf, size_t size)
  186. {
  187. struct omap_dss_device *dssdev = to_dss_device(dev);
  188. unsigned long mirror;
  189. int r;
  190. if (!dssdev->set_mirror || !dssdev->get_mirror)
  191. return -ENOENT;
  192. mirror = simple_strtoul(buf, NULL, 0);
  193. r = dssdev->set_mirror(dssdev, mirror);
  194. if (r)
  195. return r;
  196. return size;
  197. }
  198. static ssize_t display_wss_show(struct device *dev,
  199. struct device_attribute *attr, char *buf)
  200. {
  201. struct omap_dss_device *dssdev = to_dss_device(dev);
  202. unsigned int wss;
  203. if (!dssdev->get_wss)
  204. return -ENOENT;
  205. wss = dssdev->get_wss(dssdev);
  206. return snprintf(buf, PAGE_SIZE, "0x%05x\n", wss);
  207. }
  208. static ssize_t display_wss_store(struct device *dev,
  209. struct device_attribute *attr, const char *buf, size_t size)
  210. {
  211. struct omap_dss_device *dssdev = to_dss_device(dev);
  212. unsigned long wss;
  213. int r;
  214. if (!dssdev->get_wss || !dssdev->set_wss)
  215. return -ENOENT;
  216. if (strict_strtoul(buf, 0, &wss))
  217. return -EINVAL;
  218. if (wss > 0xfffff)
  219. return -EINVAL;
  220. r = dssdev->set_wss(dssdev, wss);
  221. if (r)
  222. return r;
  223. return size;
  224. }
  225. static DEVICE_ATTR(enabled, S_IRUGO|S_IWUSR,
  226. display_enabled_show, display_enabled_store);
  227. static DEVICE_ATTR(update_mode, S_IRUGO|S_IWUSR,
  228. display_upd_mode_show, display_upd_mode_store);
  229. static DEVICE_ATTR(tear_elim, S_IRUGO|S_IWUSR,
  230. display_tear_show, display_tear_store);
  231. static DEVICE_ATTR(timings, S_IRUGO|S_IWUSR,
  232. display_timings_show, display_timings_store);
  233. static DEVICE_ATTR(rotate, S_IRUGO|S_IWUSR,
  234. display_rotate_show, display_rotate_store);
  235. static DEVICE_ATTR(mirror, S_IRUGO|S_IWUSR,
  236. display_mirror_show, display_mirror_store);
  237. static DEVICE_ATTR(wss, S_IRUGO|S_IWUSR,
  238. display_wss_show, display_wss_store);
  239. static struct device_attribute *display_sysfs_attrs[] = {
  240. &dev_attr_enabled,
  241. &dev_attr_update_mode,
  242. &dev_attr_tear_elim,
  243. &dev_attr_timings,
  244. &dev_attr_rotate,
  245. &dev_attr_mirror,
  246. &dev_attr_wss,
  247. NULL
  248. };
  249. static void default_get_resolution(struct omap_dss_device *dssdev,
  250. u16 *xres, u16 *yres)
  251. {
  252. *xres = dssdev->panel.timings.x_res;
  253. *yres = dssdev->panel.timings.y_res;
  254. }
  255. void default_get_overlay_fifo_thresholds(enum omap_plane plane,
  256. u32 fifo_size, enum omap_burst_size *burst_size,
  257. u32 *fifo_low, u32 *fifo_high)
  258. {
  259. unsigned burst_size_bytes;
  260. *burst_size = OMAP_DSS_BURST_16x32;
  261. burst_size_bytes = 16 * 32 / 8;
  262. *fifo_high = fifo_size - 1;
  263. *fifo_low = fifo_size - burst_size_bytes;
  264. }
  265. static int default_wait_vsync(struct omap_dss_device *dssdev)
  266. {
  267. unsigned long timeout = msecs_to_jiffies(500);
  268. u32 irq;
  269. if (dssdev->type == OMAP_DISPLAY_TYPE_VENC)
  270. irq = DISPC_IRQ_EVSYNC_ODD;
  271. else
  272. irq = DISPC_IRQ_VSYNC;
  273. return omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
  274. }
  275. static int default_get_recommended_bpp(struct omap_dss_device *dssdev)
  276. {
  277. if (dssdev->panel.recommended_bpp)
  278. return dssdev->panel.recommended_bpp;
  279. switch (dssdev->type) {
  280. case OMAP_DISPLAY_TYPE_DPI:
  281. if (dssdev->phy.dpi.data_lines == 24)
  282. return 24;
  283. else
  284. return 16;
  285. case OMAP_DISPLAY_TYPE_DBI:
  286. case OMAP_DISPLAY_TYPE_DSI:
  287. if (dssdev->ctrl.pixel_size == 24)
  288. return 24;
  289. else
  290. return 16;
  291. case OMAP_DISPLAY_TYPE_VENC:
  292. case OMAP_DISPLAY_TYPE_SDI:
  293. return 24;
  294. return 24;
  295. default:
  296. BUG();
  297. }
  298. }
  299. /* Checks if replication logic should be used. Only use for active matrix,
  300. * when overlay is in RGB12U or RGB16 mode, and LCD interface is
  301. * 18bpp or 24bpp */
  302. bool dss_use_replication(struct omap_dss_device *dssdev,
  303. enum omap_color_mode mode)
  304. {
  305. int bpp;
  306. if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
  307. return false;
  308. if (dssdev->type == OMAP_DISPLAY_TYPE_DPI &&
  309. (dssdev->panel.config & OMAP_DSS_LCD_TFT) == 0)
  310. return false;
  311. switch (dssdev->type) {
  312. case OMAP_DISPLAY_TYPE_DPI:
  313. bpp = dssdev->phy.dpi.data_lines;
  314. break;
  315. case OMAP_DISPLAY_TYPE_VENC:
  316. case OMAP_DISPLAY_TYPE_SDI:
  317. bpp = 24;
  318. break;
  319. case OMAP_DISPLAY_TYPE_DBI:
  320. case OMAP_DISPLAY_TYPE_DSI:
  321. bpp = dssdev->ctrl.pixel_size;
  322. break;
  323. default:
  324. BUG();
  325. }
  326. return bpp > 16;
  327. }
  328. void dss_init_device(struct platform_device *pdev,
  329. struct omap_dss_device *dssdev)
  330. {
  331. struct device_attribute *attr;
  332. int i;
  333. int r;
  334. switch (dssdev->type) {
  335. case OMAP_DISPLAY_TYPE_DPI:
  336. #ifdef CONFIG_OMAP2_DSS_RFBI
  337. case OMAP_DISPLAY_TYPE_DBI:
  338. #endif
  339. #ifdef CONFIG_OMAP2_DSS_SDI
  340. case OMAP_DISPLAY_TYPE_SDI:
  341. #endif
  342. #ifdef CONFIG_OMAP2_DSS_DSI
  343. case OMAP_DISPLAY_TYPE_DSI:
  344. #endif
  345. #ifdef CONFIG_OMAP2_DSS_VENC
  346. case OMAP_DISPLAY_TYPE_VENC:
  347. #endif
  348. break;
  349. default:
  350. DSSERR("Support for display '%s' not compiled in.\n",
  351. dssdev->name);
  352. return;
  353. }
  354. dssdev->get_resolution = default_get_resolution;
  355. dssdev->get_recommended_bpp = default_get_recommended_bpp;
  356. dssdev->wait_vsync = default_wait_vsync;
  357. switch (dssdev->type) {
  358. case OMAP_DISPLAY_TYPE_DPI:
  359. r = dpi_init_display(dssdev);
  360. break;
  361. #ifdef CONFIG_OMAP2_DSS_RFBI
  362. case OMAP_DISPLAY_TYPE_DBI:
  363. r = rfbi_init_display(dssdev);
  364. break;
  365. #endif
  366. #ifdef CONFIG_OMAP2_DSS_VENC
  367. case OMAP_DISPLAY_TYPE_VENC:
  368. r = venc_init_display(dssdev);
  369. break;
  370. #endif
  371. #ifdef CONFIG_OMAP2_DSS_SDI
  372. case OMAP_DISPLAY_TYPE_SDI:
  373. r = sdi_init_display(dssdev);
  374. break;
  375. #endif
  376. #ifdef CONFIG_OMAP2_DSS_DSI
  377. case OMAP_DISPLAY_TYPE_DSI:
  378. r = dsi_init_display(dssdev);
  379. break;
  380. #endif
  381. default:
  382. BUG();
  383. }
  384. if (r) {
  385. DSSERR("failed to init display %s\n", dssdev->name);
  386. return;
  387. }
  388. /* create device sysfs files */
  389. i = 0;
  390. while ((attr = display_sysfs_attrs[i++]) != NULL) {
  391. r = device_create_file(&dssdev->dev, attr);
  392. if (r)
  393. DSSERR("failed to create sysfs file\n");
  394. }
  395. /* create display? sysfs links */
  396. r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj,
  397. dev_name(&dssdev->dev));
  398. if (r)
  399. DSSERR("failed to create sysfs display link\n");
  400. }
  401. void dss_uninit_device(struct platform_device *pdev,
  402. struct omap_dss_device *dssdev)
  403. {
  404. struct device_attribute *attr;
  405. int i = 0;
  406. sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev));
  407. while ((attr = display_sysfs_attrs[i++]) != NULL)
  408. device_remove_file(&dssdev->dev, attr);
  409. if (dssdev->manager)
  410. dssdev->manager->unset_device(dssdev->manager);
  411. }
  412. static int dss_suspend_device(struct device *dev, void *data)
  413. {
  414. int r;
  415. struct omap_dss_device *dssdev = to_dss_device(dev);
  416. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  417. dssdev->activate_after_resume = false;
  418. return 0;
  419. }
  420. if (!dssdev->suspend) {
  421. DSSERR("display '%s' doesn't implement suspend\n",
  422. dssdev->name);
  423. return -ENOSYS;
  424. }
  425. r = dssdev->suspend(dssdev);
  426. if (r)
  427. return r;
  428. dssdev->activate_after_resume = true;
  429. return 0;
  430. }
  431. int dss_suspend_all_devices(void)
  432. {
  433. int r;
  434. struct bus_type *bus = dss_get_bus();
  435. r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
  436. if (r) {
  437. /* resume all displays that were suspended */
  438. dss_resume_all_devices();
  439. return r;
  440. }
  441. return 0;
  442. }
  443. static int dss_resume_device(struct device *dev, void *data)
  444. {
  445. int r;
  446. struct omap_dss_device *dssdev = to_dss_device(dev);
  447. if (dssdev->activate_after_resume && dssdev->resume) {
  448. r = dssdev->resume(dssdev);
  449. if (r)
  450. return r;
  451. }
  452. dssdev->activate_after_resume = false;
  453. return 0;
  454. }
  455. int dss_resume_all_devices(void)
  456. {
  457. struct bus_type *bus = dss_get_bus();
  458. return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
  459. }
  460. static int dss_disable_device(struct device *dev, void *data)
  461. {
  462. struct omap_dss_device *dssdev = to_dss_device(dev);
  463. dssdev->disable(dssdev);
  464. return 0;
  465. }
  466. void dss_disable_all_devices(void)
  467. {
  468. struct bus_type *bus = dss_get_bus();
  469. bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
  470. }
  471. void omap_dss_get_device(struct omap_dss_device *dssdev)
  472. {
  473. get_device(&dssdev->dev);
  474. }
  475. EXPORT_SYMBOL(omap_dss_get_device);
  476. void omap_dss_put_device(struct omap_dss_device *dssdev)
  477. {
  478. put_device(&dssdev->dev);
  479. }
  480. EXPORT_SYMBOL(omap_dss_put_device);
  481. /* ref count of the found device is incremented. ref count
  482. * of from-device is decremented. */
  483. struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
  484. {
  485. struct device *dev;
  486. struct device *dev_start = NULL;
  487. struct omap_dss_device *dssdev = NULL;
  488. int match(struct device *dev, void *data)
  489. {
  490. /* skip panels connected to controllers */
  491. if (to_dss_device(dev)->panel.ctrl)
  492. return 0;
  493. return 1;
  494. }
  495. if (from)
  496. dev_start = &from->dev;
  497. dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
  498. if (dev)
  499. dssdev = to_dss_device(dev);
  500. if (from)
  501. put_device(&from->dev);
  502. return dssdev;
  503. }
  504. EXPORT_SYMBOL(omap_dss_get_next_device);
  505. struct omap_dss_device *omap_dss_find_device(void *data,
  506. int (*match)(struct omap_dss_device *dssdev, void *data))
  507. {
  508. struct omap_dss_device *dssdev = NULL;
  509. while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
  510. if (match(dssdev, data))
  511. return dssdev;
  512. }
  513. return NULL;
  514. }
  515. EXPORT_SYMBOL(omap_dss_find_device);
  516. int omap_dss_start_device(struct omap_dss_device *dssdev)
  517. {
  518. int r;
  519. if (!dssdev->driver) {
  520. DSSDBG("no driver\n");
  521. r = -ENODEV;
  522. goto err0;
  523. }
  524. if (dssdev->ctrl.panel && !dssdev->ctrl.panel->driver) {
  525. DSSDBG("no panel driver\n");
  526. r = -ENODEV;
  527. goto err0;
  528. }
  529. if (!try_module_get(dssdev->dev.driver->owner)) {
  530. r = -ENODEV;
  531. goto err0;
  532. }
  533. if (dssdev->ctrl.panel) {
  534. if (!try_module_get(dssdev->ctrl.panel->dev.driver->owner)) {
  535. r = -ENODEV;
  536. goto err1;
  537. }
  538. }
  539. return 0;
  540. err1:
  541. module_put(dssdev->dev.driver->owner);
  542. err0:
  543. return r;
  544. }
  545. EXPORT_SYMBOL(omap_dss_start_device);
  546. void omap_dss_stop_device(struct omap_dss_device *dssdev)
  547. {
  548. if (dssdev->ctrl.panel)
  549. module_put(dssdev->ctrl.panel->dev.driver->owner);
  550. module_put(dssdev->dev.driver->owner);
  551. }
  552. EXPORT_SYMBOL(omap_dss_stop_device);