display.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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/platform_device.h>
  27. #include <plat/display.h>
  28. #include "dss.h"
  29. static ssize_t display_enabled_show(struct device *dev,
  30. struct device_attribute *attr, char *buf)
  31. {
  32. struct omap_dss_device *dssdev = to_dss_device(dev);
  33. bool enabled = dssdev->state != OMAP_DSS_DISPLAY_DISABLED;
  34. return snprintf(buf, PAGE_SIZE, "%d\n", enabled);
  35. }
  36. static ssize_t display_enabled_store(struct device *dev,
  37. struct device_attribute *attr,
  38. const char *buf, size_t size)
  39. {
  40. struct omap_dss_device *dssdev = to_dss_device(dev);
  41. bool enabled, r;
  42. enabled = simple_strtoul(buf, NULL, 10);
  43. if (enabled != (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)) {
  44. if (enabled) {
  45. r = dssdev->driver->enable(dssdev);
  46. if (r)
  47. return r;
  48. } else {
  49. dssdev->driver->disable(dssdev);
  50. }
  51. }
  52. return size;
  53. }
  54. static ssize_t display_upd_mode_show(struct device *dev,
  55. struct device_attribute *attr, char *buf)
  56. {
  57. struct omap_dss_device *dssdev = to_dss_device(dev);
  58. enum omap_dss_update_mode mode = OMAP_DSS_UPDATE_AUTO;
  59. if (dssdev->driver->get_update_mode)
  60. mode = dssdev->driver->get_update_mode(dssdev);
  61. return snprintf(buf, PAGE_SIZE, "%d\n", mode);
  62. }
  63. static ssize_t display_upd_mode_store(struct device *dev,
  64. struct device_attribute *attr,
  65. const char *buf, size_t size)
  66. {
  67. struct omap_dss_device *dssdev = to_dss_device(dev);
  68. int val, r;
  69. enum omap_dss_update_mode mode;
  70. if (!dssdev->driver->set_update_mode)
  71. return -EINVAL;
  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. case OMAP_DISPLAY_TYPE_HDMI:
  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_HDMI:
  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. r = dpi_init_display(dssdev);
  330. break;
  331. #endif
  332. #ifdef CONFIG_OMAP2_DSS_RFBI
  333. case OMAP_DISPLAY_TYPE_DBI:
  334. r = rfbi_init_display(dssdev);
  335. break;
  336. #endif
  337. #ifdef CONFIG_OMAP2_DSS_VENC
  338. case OMAP_DISPLAY_TYPE_VENC:
  339. r = venc_init_display(dssdev);
  340. break;
  341. #endif
  342. #ifdef CONFIG_OMAP2_DSS_SDI
  343. case OMAP_DISPLAY_TYPE_SDI:
  344. r = sdi_init_display(dssdev);
  345. break;
  346. #endif
  347. #ifdef CONFIG_OMAP2_DSS_DSI
  348. case OMAP_DISPLAY_TYPE_DSI:
  349. r = dsi_init_display(dssdev);
  350. break;
  351. #endif
  352. default:
  353. DSSERR("Support for display '%s' not compiled in.\n",
  354. dssdev->name);
  355. return;
  356. }
  357. if (r) {
  358. DSSERR("failed to init display %s\n", dssdev->name);
  359. return;
  360. }
  361. /* create device sysfs files */
  362. i = 0;
  363. while ((attr = display_sysfs_attrs[i++]) != NULL) {
  364. r = device_create_file(&dssdev->dev, attr);
  365. if (r)
  366. DSSERR("failed to create sysfs file\n");
  367. }
  368. /* create display? sysfs links */
  369. r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj,
  370. dev_name(&dssdev->dev));
  371. if (r)
  372. DSSERR("failed to create sysfs display link\n");
  373. }
  374. void dss_uninit_device(struct platform_device *pdev,
  375. struct omap_dss_device *dssdev)
  376. {
  377. struct device_attribute *attr;
  378. int i = 0;
  379. sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev));
  380. while ((attr = display_sysfs_attrs[i++]) != NULL)
  381. device_remove_file(&dssdev->dev, attr);
  382. if (dssdev->manager)
  383. dssdev->manager->unset_device(dssdev->manager);
  384. }
  385. static int dss_suspend_device(struct device *dev, void *data)
  386. {
  387. int r;
  388. struct omap_dss_device *dssdev = to_dss_device(dev);
  389. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  390. dssdev->activate_after_resume = false;
  391. return 0;
  392. }
  393. if (!dssdev->driver->suspend) {
  394. DSSERR("display '%s' doesn't implement suspend\n",
  395. dssdev->name);
  396. return -ENOSYS;
  397. }
  398. r = dssdev->driver->suspend(dssdev);
  399. if (r)
  400. return r;
  401. dssdev->activate_after_resume = true;
  402. return 0;
  403. }
  404. int dss_suspend_all_devices(void)
  405. {
  406. int r;
  407. struct bus_type *bus = dss_get_bus();
  408. r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
  409. if (r) {
  410. /* resume all displays that were suspended */
  411. dss_resume_all_devices();
  412. return r;
  413. }
  414. return 0;
  415. }
  416. static int dss_resume_device(struct device *dev, void *data)
  417. {
  418. int r;
  419. struct omap_dss_device *dssdev = to_dss_device(dev);
  420. if (dssdev->activate_after_resume && dssdev->driver->resume) {
  421. r = dssdev->driver->resume(dssdev);
  422. if (r)
  423. return r;
  424. }
  425. dssdev->activate_after_resume = false;
  426. return 0;
  427. }
  428. int dss_resume_all_devices(void)
  429. {
  430. struct bus_type *bus = dss_get_bus();
  431. return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
  432. }
  433. static int dss_disable_device(struct device *dev, void *data)
  434. {
  435. struct omap_dss_device *dssdev = to_dss_device(dev);
  436. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
  437. dssdev->driver->disable(dssdev);
  438. return 0;
  439. }
  440. void dss_disable_all_devices(void)
  441. {
  442. struct bus_type *bus = dss_get_bus();
  443. bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
  444. }
  445. void omap_dss_get_device(struct omap_dss_device *dssdev)
  446. {
  447. get_device(&dssdev->dev);
  448. }
  449. EXPORT_SYMBOL(omap_dss_get_device);
  450. void omap_dss_put_device(struct omap_dss_device *dssdev)
  451. {
  452. put_device(&dssdev->dev);
  453. }
  454. EXPORT_SYMBOL(omap_dss_put_device);
  455. /* ref count of the found device is incremented. ref count
  456. * of from-device is decremented. */
  457. struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
  458. {
  459. struct device *dev;
  460. struct device *dev_start = NULL;
  461. struct omap_dss_device *dssdev = NULL;
  462. int match(struct device *dev, void *data)
  463. {
  464. return 1;
  465. }
  466. if (from)
  467. dev_start = &from->dev;
  468. dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
  469. if (dev)
  470. dssdev = to_dss_device(dev);
  471. if (from)
  472. put_device(&from->dev);
  473. return dssdev;
  474. }
  475. EXPORT_SYMBOL(omap_dss_get_next_device);
  476. struct omap_dss_device *omap_dss_find_device(void *data,
  477. int (*match)(struct omap_dss_device *dssdev, void *data))
  478. {
  479. struct omap_dss_device *dssdev = NULL;
  480. while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
  481. if (match(dssdev, data))
  482. return dssdev;
  483. }
  484. return NULL;
  485. }
  486. EXPORT_SYMBOL(omap_dss_find_device);
  487. int omap_dss_start_device(struct omap_dss_device *dssdev)
  488. {
  489. if (!dssdev->driver) {
  490. DSSDBG("no driver\n");
  491. return -ENODEV;
  492. }
  493. if (!try_module_get(dssdev->dev.driver->owner)) {
  494. return -ENODEV;
  495. }
  496. return 0;
  497. }
  498. EXPORT_SYMBOL(omap_dss_start_device);
  499. void omap_dss_stop_device(struct omap_dss_device *dssdev)
  500. {
  501. module_put(dssdev->dev.driver->owner);
  502. }
  503. EXPORT_SYMBOL(omap_dss_stop_device);