core.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*
  2. * linux/drivers/video/omap2/dss/core.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 "CORE"
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/clk.h>
  26. #include <linux/err.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/seq_file.h>
  29. #include <linux/debugfs.h>
  30. #include <linux/io.h>
  31. #include <linux/device.h>
  32. #include <linux/regulator/consumer.h>
  33. #include <plat/display.h>
  34. #include "dss.h"
  35. #include "dss_features.h"
  36. static struct {
  37. struct platform_device *pdev;
  38. struct regulator *vdds_dsi_reg;
  39. struct regulator *vdds_sdi_reg;
  40. } core;
  41. static char *def_disp_name;
  42. module_param_named(def_disp, def_disp_name, charp, 0);
  43. MODULE_PARM_DESC(def_disp_name, "default display name");
  44. #ifdef DEBUG
  45. unsigned int dss_debug;
  46. module_param_named(debug, dss_debug, bool, 0644);
  47. #endif
  48. /* REGULATORS */
  49. struct regulator *dss_get_vdds_dsi(void)
  50. {
  51. struct regulator *reg;
  52. if (core.vdds_dsi_reg != NULL)
  53. return core.vdds_dsi_reg;
  54. reg = regulator_get(&core.pdev->dev, "vdds_dsi");
  55. if (!IS_ERR(reg))
  56. core.vdds_dsi_reg = reg;
  57. return reg;
  58. }
  59. struct regulator *dss_get_vdds_sdi(void)
  60. {
  61. struct regulator *reg;
  62. if (core.vdds_sdi_reg != NULL)
  63. return core.vdds_sdi_reg;
  64. reg = regulator_get(&core.pdev->dev, "vdds_sdi");
  65. if (!IS_ERR(reg))
  66. core.vdds_sdi_reg = reg;
  67. return reg;
  68. }
  69. #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
  70. static int dss_debug_show(struct seq_file *s, void *unused)
  71. {
  72. void (*func)(struct seq_file *) = s->private;
  73. func(s);
  74. return 0;
  75. }
  76. static int dss_debug_open(struct inode *inode, struct file *file)
  77. {
  78. return single_open(file, dss_debug_show, inode->i_private);
  79. }
  80. static const struct file_operations dss_debug_fops = {
  81. .open = dss_debug_open,
  82. .read = seq_read,
  83. .llseek = seq_lseek,
  84. .release = single_release,
  85. };
  86. static struct dentry *dss_debugfs_dir;
  87. static int dss_initialize_debugfs(void)
  88. {
  89. dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
  90. if (IS_ERR(dss_debugfs_dir)) {
  91. int err = PTR_ERR(dss_debugfs_dir);
  92. dss_debugfs_dir = NULL;
  93. return err;
  94. }
  95. debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
  96. &dss_debug_dump_clocks, &dss_debug_fops);
  97. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  98. debugfs_create_file("dispc_irq", S_IRUGO, dss_debugfs_dir,
  99. &dispc_dump_irqs, &dss_debug_fops);
  100. #endif
  101. #if defined(CONFIG_OMAP2_DSS_DSI) && defined(CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS)
  102. debugfs_create_file("dsi_irq", S_IRUGO, dss_debugfs_dir,
  103. &dsi_dump_irqs, &dss_debug_fops);
  104. #endif
  105. debugfs_create_file("dss", S_IRUGO, dss_debugfs_dir,
  106. &dss_dump_regs, &dss_debug_fops);
  107. debugfs_create_file("dispc", S_IRUGO, dss_debugfs_dir,
  108. &dispc_dump_regs, &dss_debug_fops);
  109. #ifdef CONFIG_OMAP2_DSS_RFBI
  110. debugfs_create_file("rfbi", S_IRUGO, dss_debugfs_dir,
  111. &rfbi_dump_regs, &dss_debug_fops);
  112. #endif
  113. #ifdef CONFIG_OMAP2_DSS_DSI
  114. debugfs_create_file("dsi", S_IRUGO, dss_debugfs_dir,
  115. &dsi_dump_regs, &dss_debug_fops);
  116. #endif
  117. #ifdef CONFIG_OMAP2_DSS_VENC
  118. debugfs_create_file("venc", S_IRUGO, dss_debugfs_dir,
  119. &venc_dump_regs, &dss_debug_fops);
  120. #endif
  121. return 0;
  122. }
  123. static void dss_uninitialize_debugfs(void)
  124. {
  125. if (dss_debugfs_dir)
  126. debugfs_remove_recursive(dss_debugfs_dir);
  127. }
  128. #else /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
  129. static inline int dss_initialize_debugfs(void)
  130. {
  131. return 0;
  132. }
  133. static inline void dss_uninitialize_debugfs(void)
  134. {
  135. }
  136. #endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
  137. /* PLATFORM DEVICE */
  138. static int omap_dss_probe(struct platform_device *pdev)
  139. {
  140. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  141. int skip_init = 0;
  142. int r;
  143. int i;
  144. core.pdev = pdev;
  145. dss_features_init();
  146. dss_init_overlay_managers(pdev);
  147. dss_init_overlays(pdev);
  148. r = dss_init_platform_driver();
  149. if (r) {
  150. DSSERR("Failed to initialize DSS platform driver\n");
  151. goto err_dss;
  152. }
  153. /* keep clocks enabled to prevent context saves/restores during init */
  154. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
  155. r = rfbi_init_platform_driver();
  156. if (r) {
  157. DSSERR("Failed to initialize rfbi platform driver\n");
  158. goto err_rfbi;
  159. }
  160. r = dpi_init(pdev);
  161. if (r) {
  162. DSSERR("Failed to initialize dpi\n");
  163. goto err_dpi;
  164. }
  165. r = dispc_init_platform_driver();
  166. if (r) {
  167. DSSERR("Failed to initialize dispc platform driver\n");
  168. goto err_dispc;
  169. }
  170. r = venc_init_platform_driver();
  171. if (r) {
  172. DSSERR("Failed to initialize venc platform driver\n");
  173. goto err_venc;
  174. }
  175. #ifdef CONFIG_FB_OMAP_BOOTLOADER_INIT
  176. /* DISPC_CONTROL */
  177. if (omap_readl(0x48050440) & 1) /* LCD enabled? */
  178. skip_init = 1;
  179. #endif
  180. if (cpu_is_omap34xx()) {
  181. r = sdi_init(skip_init);
  182. if (r) {
  183. DSSERR("Failed to initialize SDI\n");
  184. goto err_sdi;
  185. }
  186. r = dsi_init(pdev);
  187. if (r) {
  188. DSSERR("Failed to initialize DSI\n");
  189. goto err_dsi;
  190. }
  191. }
  192. r = dss_initialize_debugfs();
  193. if (r)
  194. goto err_debugfs;
  195. for (i = 0; i < pdata->num_devices; ++i) {
  196. struct omap_dss_device *dssdev = pdata->devices[i];
  197. r = omap_dss_register_device(dssdev);
  198. if (r) {
  199. DSSERR("device %d %s register failed %d\n", i,
  200. dssdev->name ?: "unnamed", r);
  201. while (--i >= 0)
  202. omap_dss_unregister_device(pdata->devices[i]);
  203. goto err_register;
  204. }
  205. if (def_disp_name && strcmp(def_disp_name, dssdev->name) == 0)
  206. pdata->default_device = dssdev;
  207. }
  208. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
  209. return 0;
  210. err_register:
  211. dss_uninitialize_debugfs();
  212. err_debugfs:
  213. if (cpu_is_omap34xx())
  214. dsi_exit();
  215. err_dsi:
  216. if (cpu_is_omap34xx())
  217. sdi_exit();
  218. err_sdi:
  219. venc_uninit_platform_driver();
  220. err_venc:
  221. dispc_uninit_platform_driver();
  222. err_dispc:
  223. dpi_exit();
  224. err_dpi:
  225. rfbi_uninit_platform_driver();
  226. err_rfbi:
  227. dss_uninit_platform_driver();
  228. err_dss:
  229. return r;
  230. }
  231. static int omap_dss_remove(struct platform_device *pdev)
  232. {
  233. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  234. int i;
  235. dss_uninitialize_debugfs();
  236. venc_uninit_platform_driver();
  237. dispc_uninit_platform_driver();
  238. dpi_exit();
  239. rfbi_uninit_platform_driver();
  240. if (cpu_is_omap34xx()) {
  241. dsi_exit();
  242. sdi_exit();
  243. }
  244. dss_uninit_platform_driver();
  245. dss_uninit_overlays(pdev);
  246. dss_uninit_overlay_managers(pdev);
  247. for (i = 0; i < pdata->num_devices; ++i)
  248. omap_dss_unregister_device(pdata->devices[i]);
  249. return 0;
  250. }
  251. static void omap_dss_shutdown(struct platform_device *pdev)
  252. {
  253. DSSDBG("shutdown\n");
  254. dss_disable_all_devices();
  255. }
  256. static int omap_dss_suspend(struct platform_device *pdev, pm_message_t state)
  257. {
  258. DSSDBG("suspend %d\n", state.event);
  259. return dss_suspend_all_devices();
  260. }
  261. static int omap_dss_resume(struct platform_device *pdev)
  262. {
  263. DSSDBG("resume\n");
  264. return dss_resume_all_devices();
  265. }
  266. static struct platform_driver omap_dss_driver = {
  267. .probe = omap_dss_probe,
  268. .remove = omap_dss_remove,
  269. .shutdown = omap_dss_shutdown,
  270. .suspend = omap_dss_suspend,
  271. .resume = omap_dss_resume,
  272. .driver = {
  273. .name = "omapdss",
  274. .owner = THIS_MODULE,
  275. },
  276. };
  277. /* BUS */
  278. static int dss_bus_match(struct device *dev, struct device_driver *driver)
  279. {
  280. struct omap_dss_device *dssdev = to_dss_device(dev);
  281. DSSDBG("bus_match. dev %s/%s, drv %s\n",
  282. dev_name(dev), dssdev->driver_name, driver->name);
  283. return strcmp(dssdev->driver_name, driver->name) == 0;
  284. }
  285. static ssize_t device_name_show(struct device *dev,
  286. struct device_attribute *attr, char *buf)
  287. {
  288. struct omap_dss_device *dssdev = to_dss_device(dev);
  289. return snprintf(buf, PAGE_SIZE, "%s\n",
  290. dssdev->name ?
  291. dssdev->name : "");
  292. }
  293. static struct device_attribute default_dev_attrs[] = {
  294. __ATTR(name, S_IRUGO, device_name_show, NULL),
  295. __ATTR_NULL,
  296. };
  297. static ssize_t driver_name_show(struct device_driver *drv, char *buf)
  298. {
  299. struct omap_dss_driver *dssdrv = to_dss_driver(drv);
  300. return snprintf(buf, PAGE_SIZE, "%s\n",
  301. dssdrv->driver.name ?
  302. dssdrv->driver.name : "");
  303. }
  304. static struct driver_attribute default_drv_attrs[] = {
  305. __ATTR(name, S_IRUGO, driver_name_show, NULL),
  306. __ATTR_NULL,
  307. };
  308. static struct bus_type dss_bus_type = {
  309. .name = "omapdss",
  310. .match = dss_bus_match,
  311. .dev_attrs = default_dev_attrs,
  312. .drv_attrs = default_drv_attrs,
  313. };
  314. static void dss_bus_release(struct device *dev)
  315. {
  316. DSSDBG("bus_release\n");
  317. }
  318. static struct device dss_bus = {
  319. .release = dss_bus_release,
  320. };
  321. struct bus_type *dss_get_bus(void)
  322. {
  323. return &dss_bus_type;
  324. }
  325. /* DRIVER */
  326. static int dss_driver_probe(struct device *dev)
  327. {
  328. int r;
  329. struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
  330. struct omap_dss_device *dssdev = to_dss_device(dev);
  331. struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
  332. bool force;
  333. DSSDBG("driver_probe: dev %s/%s, drv %s\n",
  334. dev_name(dev), dssdev->driver_name,
  335. dssdrv->driver.name);
  336. dss_init_device(core.pdev, dssdev);
  337. force = pdata->default_device == dssdev;
  338. dss_recheck_connections(dssdev, force);
  339. r = dssdrv->probe(dssdev);
  340. if (r) {
  341. DSSERR("driver probe failed: %d\n", r);
  342. dss_uninit_device(core.pdev, dssdev);
  343. return r;
  344. }
  345. DSSDBG("probe done for device %s\n", dev_name(dev));
  346. dssdev->driver = dssdrv;
  347. return 0;
  348. }
  349. static int dss_driver_remove(struct device *dev)
  350. {
  351. struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
  352. struct omap_dss_device *dssdev = to_dss_device(dev);
  353. DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
  354. dssdev->driver_name);
  355. dssdrv->remove(dssdev);
  356. dss_uninit_device(core.pdev, dssdev);
  357. dssdev->driver = NULL;
  358. return 0;
  359. }
  360. int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
  361. {
  362. dssdriver->driver.bus = &dss_bus_type;
  363. dssdriver->driver.probe = dss_driver_probe;
  364. dssdriver->driver.remove = dss_driver_remove;
  365. if (dssdriver->get_resolution == NULL)
  366. dssdriver->get_resolution = omapdss_default_get_resolution;
  367. if (dssdriver->get_recommended_bpp == NULL)
  368. dssdriver->get_recommended_bpp =
  369. omapdss_default_get_recommended_bpp;
  370. return driver_register(&dssdriver->driver);
  371. }
  372. EXPORT_SYMBOL(omap_dss_register_driver);
  373. void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
  374. {
  375. driver_unregister(&dssdriver->driver);
  376. }
  377. EXPORT_SYMBOL(omap_dss_unregister_driver);
  378. /* DEVICE */
  379. static void reset_device(struct device *dev, int check)
  380. {
  381. u8 *dev_p = (u8 *)dev;
  382. u8 *dev_end = dev_p + sizeof(*dev);
  383. void *saved_pdata;
  384. saved_pdata = dev->platform_data;
  385. if (check) {
  386. /*
  387. * Check if there is any other setting than platform_data
  388. * in struct device; warn that these will be reset by our
  389. * init.
  390. */
  391. dev->platform_data = NULL;
  392. while (dev_p < dev_end) {
  393. if (*dev_p) {
  394. WARN("%s: struct device fields will be "
  395. "discarded\n",
  396. __func__);
  397. break;
  398. }
  399. dev_p++;
  400. }
  401. }
  402. memset(dev, 0, sizeof(*dev));
  403. dev->platform_data = saved_pdata;
  404. }
  405. static void omap_dss_dev_release(struct device *dev)
  406. {
  407. reset_device(dev, 0);
  408. }
  409. int omap_dss_register_device(struct omap_dss_device *dssdev)
  410. {
  411. static int dev_num;
  412. WARN_ON(!dssdev->driver_name);
  413. reset_device(&dssdev->dev, 1);
  414. dssdev->dev.bus = &dss_bus_type;
  415. dssdev->dev.parent = &dss_bus;
  416. dssdev->dev.release = omap_dss_dev_release;
  417. dev_set_name(&dssdev->dev, "display%d", dev_num++);
  418. return device_register(&dssdev->dev);
  419. }
  420. void omap_dss_unregister_device(struct omap_dss_device *dssdev)
  421. {
  422. device_unregister(&dssdev->dev);
  423. }
  424. /* BUS */
  425. static int omap_dss_bus_register(void)
  426. {
  427. int r;
  428. r = bus_register(&dss_bus_type);
  429. if (r) {
  430. DSSERR("bus register failed\n");
  431. return r;
  432. }
  433. dev_set_name(&dss_bus, "omapdss");
  434. r = device_register(&dss_bus);
  435. if (r) {
  436. DSSERR("bus driver register failed\n");
  437. bus_unregister(&dss_bus_type);
  438. return r;
  439. }
  440. return 0;
  441. }
  442. /* INIT */
  443. #ifdef CONFIG_OMAP2_DSS_MODULE
  444. static void omap_dss_bus_unregister(void)
  445. {
  446. device_unregister(&dss_bus);
  447. bus_unregister(&dss_bus_type);
  448. }
  449. static int __init omap_dss_init(void)
  450. {
  451. int r;
  452. r = omap_dss_bus_register();
  453. if (r)
  454. return r;
  455. r = platform_driver_register(&omap_dss_driver);
  456. if (r) {
  457. omap_dss_bus_unregister();
  458. return r;
  459. }
  460. return 0;
  461. }
  462. static void __exit omap_dss_exit(void)
  463. {
  464. if (core.vdds_dsi_reg != NULL) {
  465. regulator_put(core.vdds_dsi_reg);
  466. core.vdds_dsi_reg = NULL;
  467. }
  468. if (core.vdds_sdi_reg != NULL) {
  469. regulator_put(core.vdds_sdi_reg);
  470. core.vdds_sdi_reg = NULL;
  471. }
  472. platform_driver_unregister(&omap_dss_driver);
  473. omap_dss_bus_unregister();
  474. }
  475. module_init(omap_dss_init);
  476. module_exit(omap_dss_exit);
  477. #else
  478. static int __init omap_dss_init(void)
  479. {
  480. return omap_dss_bus_register();
  481. }
  482. static int __init omap_dss_init2(void)
  483. {
  484. return platform_driver_register(&omap_dss_driver);
  485. }
  486. core_initcall(omap_dss_init);
  487. device_initcall(omap_dss_init2);
  488. #endif
  489. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  490. MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
  491. MODULE_LICENSE("GPL v2");