display.c 14 KB

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