display.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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->driver->get_rotate)
  156. return -ENOENT;
  157. rotate = dssdev->driver->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->driver->set_rotate || !dssdev->driver->get_rotate)
  167. return -ENOENT;
  168. rot = simple_strtoul(buf, NULL, 0);
  169. r = dssdev->driver->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->driver->get_mirror)
  180. return -ENOENT;
  181. mirror = dssdev->driver->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->driver->set_mirror || !dssdev->driver->get_mirror)
  191. return -ENOENT;
  192. mirror = simple_strtoul(buf, NULL, 0);
  193. r = dssdev->driver->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_get_recommended_bpp(struct omap_dss_device *dssdev)
  266. {
  267. if (dssdev->panel.recommended_bpp)
  268. return dssdev->panel.recommended_bpp;
  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. /* Checks if replication logic should be used. Only use for active matrix,
  290. * when overlay is in RGB12U or RGB16 mode, and LCD interface is
  291. * 18bpp or 24bpp */
  292. bool dss_use_replication(struct omap_dss_device *dssdev,
  293. enum omap_color_mode mode)
  294. {
  295. int bpp;
  296. if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
  297. return false;
  298. if (dssdev->type == OMAP_DISPLAY_TYPE_DPI &&
  299. (dssdev->panel.config & OMAP_DSS_LCD_TFT) == 0)
  300. return false;
  301. switch (dssdev->type) {
  302. case OMAP_DISPLAY_TYPE_DPI:
  303. bpp = dssdev->phy.dpi.data_lines;
  304. break;
  305. case OMAP_DISPLAY_TYPE_VENC:
  306. case OMAP_DISPLAY_TYPE_SDI:
  307. bpp = 24;
  308. break;
  309. case OMAP_DISPLAY_TYPE_DBI:
  310. case OMAP_DISPLAY_TYPE_DSI:
  311. bpp = dssdev->ctrl.pixel_size;
  312. break;
  313. default:
  314. BUG();
  315. }
  316. return bpp > 16;
  317. }
  318. void dss_init_device(struct platform_device *pdev,
  319. struct omap_dss_device *dssdev)
  320. {
  321. struct device_attribute *attr;
  322. int i;
  323. int r;
  324. switch (dssdev->type) {
  325. case OMAP_DISPLAY_TYPE_DPI:
  326. #ifdef CONFIG_OMAP2_DSS_RFBI
  327. case OMAP_DISPLAY_TYPE_DBI:
  328. #endif
  329. #ifdef CONFIG_OMAP2_DSS_SDI
  330. case OMAP_DISPLAY_TYPE_SDI:
  331. #endif
  332. #ifdef CONFIG_OMAP2_DSS_DSI
  333. case OMAP_DISPLAY_TYPE_DSI:
  334. #endif
  335. #ifdef CONFIG_OMAP2_DSS_VENC
  336. case OMAP_DISPLAY_TYPE_VENC:
  337. #endif
  338. break;
  339. default:
  340. DSSERR("Support for display '%s' not compiled in.\n",
  341. dssdev->name);
  342. return;
  343. }
  344. dssdev->get_resolution = default_get_resolution;
  345. dssdev->get_recommended_bpp = default_get_recommended_bpp;
  346. switch (dssdev->type) {
  347. case OMAP_DISPLAY_TYPE_DPI:
  348. r = dpi_init_display(dssdev);
  349. break;
  350. #ifdef CONFIG_OMAP2_DSS_RFBI
  351. case OMAP_DISPLAY_TYPE_DBI:
  352. r = rfbi_init_display(dssdev);
  353. break;
  354. #endif
  355. #ifdef CONFIG_OMAP2_DSS_VENC
  356. case OMAP_DISPLAY_TYPE_VENC:
  357. r = venc_init_display(dssdev);
  358. break;
  359. #endif
  360. #ifdef CONFIG_OMAP2_DSS_SDI
  361. case OMAP_DISPLAY_TYPE_SDI:
  362. r = sdi_init_display(dssdev);
  363. break;
  364. #endif
  365. #ifdef CONFIG_OMAP2_DSS_DSI
  366. case OMAP_DISPLAY_TYPE_DSI:
  367. r = dsi_init_display(dssdev);
  368. break;
  369. #endif
  370. default:
  371. BUG();
  372. }
  373. if (r) {
  374. DSSERR("failed to init display %s\n", dssdev->name);
  375. return;
  376. }
  377. /* create device sysfs files */
  378. i = 0;
  379. while ((attr = display_sysfs_attrs[i++]) != NULL) {
  380. r = device_create_file(&dssdev->dev, attr);
  381. if (r)
  382. DSSERR("failed to create sysfs file\n");
  383. }
  384. /* create display? sysfs links */
  385. r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj,
  386. dev_name(&dssdev->dev));
  387. if (r)
  388. DSSERR("failed to create sysfs display link\n");
  389. }
  390. void dss_uninit_device(struct platform_device *pdev,
  391. struct omap_dss_device *dssdev)
  392. {
  393. struct device_attribute *attr;
  394. int i = 0;
  395. sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev));
  396. while ((attr = display_sysfs_attrs[i++]) != NULL)
  397. device_remove_file(&dssdev->dev, attr);
  398. if (dssdev->manager)
  399. dssdev->manager->unset_device(dssdev->manager);
  400. }
  401. static int dss_suspend_device(struct device *dev, void *data)
  402. {
  403. int r;
  404. struct omap_dss_device *dssdev = to_dss_device(dev);
  405. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  406. dssdev->activate_after_resume = false;
  407. return 0;
  408. }
  409. if (!dssdev->suspend) {
  410. DSSERR("display '%s' doesn't implement suspend\n",
  411. dssdev->name);
  412. return -ENOSYS;
  413. }
  414. r = dssdev->suspend(dssdev);
  415. if (r)
  416. return r;
  417. dssdev->activate_after_resume = true;
  418. return 0;
  419. }
  420. int dss_suspend_all_devices(void)
  421. {
  422. int r;
  423. struct bus_type *bus = dss_get_bus();
  424. r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
  425. if (r) {
  426. /* resume all displays that were suspended */
  427. dss_resume_all_devices();
  428. return r;
  429. }
  430. return 0;
  431. }
  432. static int dss_resume_device(struct device *dev, void *data)
  433. {
  434. int r;
  435. struct omap_dss_device *dssdev = to_dss_device(dev);
  436. if (dssdev->activate_after_resume && dssdev->resume) {
  437. r = dssdev->resume(dssdev);
  438. if (r)
  439. return r;
  440. }
  441. dssdev->activate_after_resume = false;
  442. return 0;
  443. }
  444. int dss_resume_all_devices(void)
  445. {
  446. struct bus_type *bus = dss_get_bus();
  447. return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
  448. }
  449. static int dss_disable_device(struct device *dev, void *data)
  450. {
  451. struct omap_dss_device *dssdev = to_dss_device(dev);
  452. dssdev->disable(dssdev);
  453. return 0;
  454. }
  455. void dss_disable_all_devices(void)
  456. {
  457. struct bus_type *bus = dss_get_bus();
  458. bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
  459. }
  460. void omap_dss_get_device(struct omap_dss_device *dssdev)
  461. {
  462. get_device(&dssdev->dev);
  463. }
  464. EXPORT_SYMBOL(omap_dss_get_device);
  465. void omap_dss_put_device(struct omap_dss_device *dssdev)
  466. {
  467. put_device(&dssdev->dev);
  468. }
  469. EXPORT_SYMBOL(omap_dss_put_device);
  470. /* ref count of the found device is incremented. ref count
  471. * of from-device is decremented. */
  472. struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
  473. {
  474. struct device *dev;
  475. struct device *dev_start = NULL;
  476. struct omap_dss_device *dssdev = NULL;
  477. int match(struct device *dev, void *data)
  478. {
  479. return 1;
  480. }
  481. if (from)
  482. dev_start = &from->dev;
  483. dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
  484. if (dev)
  485. dssdev = to_dss_device(dev);
  486. if (from)
  487. put_device(&from->dev);
  488. return dssdev;
  489. }
  490. EXPORT_SYMBOL(omap_dss_get_next_device);
  491. struct omap_dss_device *omap_dss_find_device(void *data,
  492. int (*match)(struct omap_dss_device *dssdev, void *data))
  493. {
  494. struct omap_dss_device *dssdev = NULL;
  495. while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
  496. if (match(dssdev, data))
  497. return dssdev;
  498. }
  499. return NULL;
  500. }
  501. EXPORT_SYMBOL(omap_dss_find_device);
  502. int omap_dss_start_device(struct omap_dss_device *dssdev)
  503. {
  504. if (!dssdev->driver) {
  505. DSSDBG("no driver\n");
  506. return -ENODEV;
  507. }
  508. if (!try_module_get(dssdev->dev.driver->owner)) {
  509. return -ENODEV;
  510. }
  511. return 0;
  512. }
  513. EXPORT_SYMBOL(omap_dss_start_device);
  514. void omap_dss_stop_device(struct omap_dss_device *dssdev)
  515. {
  516. module_put(dssdev->dev.driver->owner);
  517. }
  518. EXPORT_SYMBOL(omap_dss_stop_device);