display.c 14 KB

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